各位看看这个函数哪不对啊,为什么不能把十六进制的字符串转成汉字呢??

erduo 2003-10-17 12:28:10
function DecodeWideString(Value:String):wideString;
var
I:Integer;
begin
Result:='';
for I:=0 to (Length(Value) div 4)-1 do begin
Result:=Result+wchar(strtoint('$'+value[I*4+1]+value[I*4+2])shl 8+strtoint('$'+Value[I*4+3]+Value[I*4+4]) );
end;

end;
...全文
91 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
pankun 2003-10-17
  • 打赏
  • 举报
回复
用不了这么麻烦吧.
ShowMessage(Format('%8.8x', [3465243]));
用Format转换就可以了.
erduo 2003-10-17
  • 打赏
  • 举报
回复
tony我用你的函数ECODEWIDESTRING转汉字时,比如“你”,我想得到的是“C3E4”,可你这个函数得的是“4F60”,所以DECODEWIDESTRING转回来时,肯定不是我想要的。
bphoenix 2003-10-17
  • 打赏
  • 举报
回复
up
herofy 2003-10-17
  • 打赏
  • 举报
回复
ok
erduo 2003-10-17
  • 打赏
  • 举报
回复
呵呵,确实是我抄的,但是用它转时总是??,成不了汉字,唉
hiflower 2003-10-17
  • 打赏
  • 举报
回复
function DecodeWideString(Value:String):wideString;
var
i:Integer;
s:string;
begin
for I:=0 to (Length(Value) div 4)-1 do
begin
s:=Copy(Value,i*4+1,4);
Result:=Result+widechar(StrToInt('$'+s));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
s:WideString='中国人';
begin
caption:=DecodeWideString(inttohex(ord(s[1]),4)+InttoHex(Ord(s[2]),4));
end;
tonylk 2003-10-17
  • 打赏
  • 举报
回复
这个函数好像是我写的嘛。。。

function EncodeWideString(Value:WideString):String;
//encode the widestring to saveable string
//2003.03.04
var
I:Integer;
begin
Result:='';
for I:=1 to Length(Value) do begin
Result:=Result+IntToHex(WORD(Value[I]) shr 8,2);
Result:=Result+IntToHex(WORD(Value[I]) and $00ff,2);
end;
end;

function DecodeWideString(Value:String):WideString;
//decode the string to widestring
//2003.03.04
var
I:Integer;
begin
Result:='';
for I:=0 to (Length(Value) div 4)-1 do begin
Result:=Result+WChar(StrToInt('$'+Value[I*4+1]+Value[I*4+2]) shl 8
+ StrToInt('$'+Value[I*4+3]+Value[I*4+4]));
end;
end;

function EncodeUnicodeSQL(Value:WideString):String;
//encode the widestring to string of unicode ascii set
//be used for search unicode char in SQL server
//2003.03.21
var
I:Integer;
begin
Result:='';
for I:=1 to Length(Value) do begin
if I>1 then begin
Result:=Result+'+';
end;
Result:=Result+'NCHAR('+IntToStr(Word(Value[I]))+')';
end;
end;

我用很正常啊,你先用EncodeWideString()将中文转成普通字符串,看看和你要使用的格式是否一样。
江山易改 2003-10-17
  • 打赏
  • 举报
回复
没什么不对呀,你函数各位好象只有输入0-9,a,b,c,d,e,f几个符号参数,但4位数中,不能够低于5000

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧