比如说“中”字,gb2312编码用十六进制表示为“0xD6D0”,Unicode编码对应为“0X4E2D”。
假如现在有一个字符串变量声明如下:
     a:='中';
如何将其转换成Unicode码保存到变量a中呢?注意:不是用“0X4E2D”来表示“中”。
      不知道说清楚了没有。望高手指点!!百分相送!

解决方案 »

  1.   

    通过Delphi的WideString类型转换,可以巧妙地实现GB2312到Unicode的编码转换.下面是实现中文编码的部分Delphi 5代码: 
    // 中文格式编码,s为Unicode String 
    function Encode2(var s:WideString):String;  
    var 
    i,len:Integer; 
    cur:Integer; 
    t:String; 
    begin 
    Result:=‘’; 
    len:=Length(s); 
    i:=1; 
    while i<=len do 
    begin 
    cur:=ord(s[i]); 
    FmtStr(t,‘%4.4X’,[cur]);  
    Result:=Result+t; 
    inc(i); 
    end; 
    end;  
      

  2.   

    请参看MSDN的APILCMapString它可以实现GB和big5和Unicode之间的转换,不需要什么对照表。
      

  3.   

    http://community.csdn.net/Expert/TopicView3.asp?id=4085935
      

  4.   

    var
      str: String;
      str_w: WideString;
    begin
      str := '中国';
      str_w := WideString(str);
      ......
    end;
    str_w里面的内容就是unicode编码的了啦.
      

  5.   

    谢谢aiirii(ari-淘金坑),函数
    Function MyUnicode(SMSG:string):String;
    var
      st:String;
      i:integer;
      a:UCS4String;
      b,c:LongWord;
      MyCh:char;
    begin
      a:=WideStringToUCS4String(SMSG);
      st:='';
      i:=0;
      b:=a[i];
      while b>0 do begin
         c:=b mod 65536;
         mych:=char(c div 256);
         st:=st+mych;
         mych:=char(c mod 256);
         st:=st+mych;
         i:=i+1;
         b:=a[i];
      end;
      Result:=st;
    end;
    正是我所要的!
      

  6.   

    真正的GB2312/GBK转Unicode应该是MultiByteToWideChar当中CodePage参数使用936(简体,950繁体,932日文...),并且还需要当前系统支持简体
    function StringToWideStringEx(const S: AnsiString; CodePage: Cardinal=936): WideString;
    var
      InputLength,
      OutputLength: Integer;
    begin
        InputLength := Length(S);
        OutputLength := MultiByteToWideChar(CodePage, 0, PAnsiChar(S), InputLength, nil, 0);
        SetLength(Result, OutputLength);
        MultiByteToWideChar(CodePage, 0, PAnsiChar(S), InputLength, PWideChar(Result), OutputLength);
    end;
      

  7.   

    to: unsigned(僵哥)
    用你的函数转换后还是显示中文,比如说原来是“你好”的,转换后还是“你好”