阿杰 发表于 2011-12-21 15:03:02

取汉字的机内码、UniCode码

//机内码 -> 汉字
Function MacCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : Integer;
Begin
ch := AiUniCode Div 256;
cl := AiUniCode Mod 256;
Result := Chr(ch) + Chr(cl);
end;

//汉字 -> 机内码
Function Chinese2MacCode(AiChinese : String) : Integer;
Var
ch, cl : Integer;
Begin
ch := Ord(AiChinese);
cl := Ord(AiChinese);
Result := (ch shl 8) + cl;
end;

//UniCode -> 汉字
Function UniCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : String;
s : String;
Begin
s := IntToHex(AiUniCode, 2);
cl := '$' + Copy(s, 1, 2);
ch := '$' + Copy(s, 3, 2);
s := Chr(StrToInt(ch)) + Chr(StrToInt(cl)) + #0;
Result := WideCharToString(pWideChar(s));
end;

//汉字 -> UniCode
Function Chinese2UniCode(AiChinese : String) : Integer;
Var
ch, cl : String;
a : array of char;
Begin
StringToWideChar(Copy(AiChinese, 1, 2), @(a), 2);
ch := IntToHex(Integer(a), 2);
cl := IntToHex(Integer(a), 2);
Result := StrToInt('$' + ch + cl);
end;

xmlpull 发表于 2011-12-22 00:25:09

{:soso_e142:}虽然看不懂 但是支持一下.!!!

upring 发表于 2015-3-31 16:51:20

汉字内码 学习一下
页: [1]
查看完整版本: 取汉字的机内码、UniCode码