ORD(“中”)为20013如何反过来将20013转换为“中” ( 积分: 100 )

  • 主题发起人 主题发起人 JeffYan
  • 开始时间 开始时间
J

JeffYan

Unregistered / Unconfirmed
GUEST, unregistred user!
ORD(“中”)为20013如何反过来将20013转换为“中”

再请教一下
如中文的“中”用ORD(“中”)为20013
如何反过来将20013转换为“中”
 
ORD(“中”)为20013如何反过来将20013转换为“中”

再请教一下
如中文的“中”用ORD(“中”)为20013
如何反过来将20013转换为“中”
 
type DChar=record Low:Byte;High:Byte;end;
var
i:word;
s:string;

begin
i:=20013;
s:=DChar(i).low+DChar(i).High;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
Wc: WideChar;
K: Integer;
begin
Wc := WideChar(widestring('中')[1]);
K := ord(Wc);
ShowMessage(widechar(k));
end;
 
http://www.delphibbs.com/keylife/iblog_show.asp?xid=13397

//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;
 
最简单的方法,只要一个强制类型转换即可:
var
UnicodeValue:Word;
...
UnicodeValue:=20013;
showmessage(WideChar(UnicodeValue));
 
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;
 
后退
顶部