随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

{感谢 robin(xuebin418@163.com)提供}

//转换
function Str_Gb2UniCode(text: string): String; 
var 
  i,len: Integer;
  cur: Integer;
  t: String;
  ws: WideString;
begin
  Result := '';
  ws := text;
  len := Length(ws);
  i := 1;
  while i <= len do
  begin
    cur := Ord(ws[i]);
    FmtStr(t,'%4.4X',[cur]);
    Result := Result + t;
    Inc(i);
  end;
end;

//恢复
function Unicode_str(text: string):string;
var
  i,len: Integer;
  ws: WideString;
begin
  ws := '';
  i := 1;
  len := Length(text);
  while i < len do
  begin
    ws := ws + Widechar(StrToInt('$' + Copy(text,i,4)));
    i := i+4;
  end;
  Result := ws;
end;

//测试
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(Str_Gb2UniCode('万一'));  //4E074E00
  ShowMessage(Unicode_str('4E074E00'));  //万一
end;

posted on 2007-12-09 21:46  万一  阅读(...)  评论(...编辑  收藏