16,748
社区成员
发帖
与我相关
我的任务
分享
type
arrByte = array of byte;
function UnicodeEncodes(s: widestring) : string;
var
i,len : Integer;
cur : Integer;
t : String;
begin
result := '';
len := Length(s);
i := 1;
while i <= len do
begin
cur := ord(s[i]);
FmtStr(t,'%4.4X',[cur]);
result := result + t;
inc(i);
end;
end;
Function DXConvertUnicode(const ChineseStr: WideString): arrByte;
var
i, k, bNo, code: LongInt;
strTotal: arrByte;
n, n1: string;
begin
k := Length(ChineseStr);
SetLength(strTotal, k*2);
strTotal[0] := 00;
bNo := 0;
For i := 1 To k do
begin
n1 := Copy(ChineseStr, i, 1);
n := UnicodeEncodes(n1);
code := StrToInt('$' + n);
strTotal[bNo] := Code div 256;
strTotal[bNo + 1] := Code And 255;
bNo := bNo + 2;
end;
Result := strTotal;
end;
function unicodeToWord(abts: TBytes): string;
var
strout: string;
ahex: Integer;
i, j: Integer;
begin
// 字符串
SetLength(strout, Length(abts) div 2);
i := 0;
j := 1;
while i < Length(abts) - 1 do
begin
ahex := abts[i];
ahex := ahex shl 8;
ahex := ahex + abts[i + 1];
strout[j] := Char(ahex);
i := i + 2;
inc(j)
end;
result := strout;
end;
function ByteArray2UnicodeString(const Arr: ArrByte; ArrBigEndian: boolean = true): WideString;
var
i: integer;
p: ArrByte;
begin
SetLength(Result, Length(Arr) div 2);
p := pointer(Result);
if ArrBigEndian then
for i := 1 to Length(Result) do
begin
p[i * 2 - 2] := Arr[i * 2 - 1];
p[i * 2 - 1] := Arr[i * 2 - 2];
end
else
move(Arr[0], p[0], Length(Result) * 2);
end;
// 字符串
String strOut;
strOut.SetLength(bts.Length / 2);
int ahex;
for (int i = 0, j = 1; i < bts.Length; j++)
{
ahex = bts[i];
ahex = ahex << 0x8;
ahex += bts[i + 1];
strOut[j] = ahex;
i += 2;
}
Caption = strOut;