delphi返回一個漢字的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[1]);
cl := Ord(AiChinese[2]);
Result := (ch shl 8) + cl;
end;

//UniCode -> 漢字
Function UniCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : String[3];
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[2];
a : array [1..2] of char;
Begin
StringToWideChar(Copy(AiChinese, 1, 2), @(a[1]), 2);
ch := IntToHex(Integer(a[2]), 2);
cl := IntToHex(Integer(a[1]), 2);
Result := StrToInt('$' + ch + cl);
end;

全文:https://zhidao.baidu.com/question/407750470.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM