比如说“中”字,gb2312编码用十六进制表示为“0xD6D0”,Unicode编码对应为“0X4E2D”。
假如现在有一个字符串变量声明如下:
a:='中';
如何将其转换成Unicode码保存到变量a中呢?注意:不是用“0X4E2D”来表示“中”。
不知道说清楚了没有。望高手指点!!百分相送!
假如现在有一个字符串变量声明如下:
a:='中';
如何将其转换成Unicode码保存到变量a中呢?注意:不是用“0X4E2D”来表示“中”。
不知道说清楚了没有。望高手指点!!百分相送!
// 中文格式编码,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;
str: String;
str_w: WideString;
begin
str := '中国';
str_w := WideString(str);
......
end;
str_w里面的内容就是unicode编码的了啦.
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;
正是我所要的!
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;
用你的函数转换后还是显示中文,比如说原来是“你好”的,转换后还是“你好”