网上文摘 小说 Flash游戏 最近更新 下载排行 资源分类 下载指南
经典编程资源 精彩不容错过
设为首页
加入收藏
联系我们
当前位置:Delphi园地技巧文章参考资料 → 取汉字的机内码、UniCode码
取汉字的机内码、UniCode码
日期:2007年12月24日 作者:stp1688 人气: 查看:[大字体 中字体 小字体]

//机内码 -> 汉字
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;  


(出处:http://www.delphibbs.com/keylife/iblog_show.asp?xid=29488)

相关文章:
·输入汉字自动产生拼音简码
·计算汉字笔划的函数
·区位码与汉字的相互转换
·Delphi下汉字输入法的编程及使用
 → 特别推荐
 → 热点TOP10
关于我们 | 广告服务 | 发布资源 | 联系站长 Copyright © 2002-2006 Delphi园地 All Rights Reserved