接收到PDU编码“4F60597D”,通过以下函数解码出现乱码"O`Y}"(原码为:你好),请高手赐教.function DecodePDU(var s:String):string;
var
i:Integer;
str:string ;
len1,len2:integer;
begin
i:=1;
str:=s;
while i < length(str) do
begin
len1:=strtoint('$'+str[i]+str[i+1]);
len2:=strtoint('$'+str[i+2]+str[i+3]);
result:=result+chr(len1)+chr(len2);
i:=i+4;
end;
end;
var
i:Integer;
str:string ;
len1,len2:integer;
begin
i:=1;
str:=s;
while i < length(str) do
begin
len1:=strtoint('$'+str[i]+str[i+1]);
len2:=strtoint('$'+str[i+2]+str[i+3]);
result:=result+chr(len1)+chr(len2);
i:=i+4;
end;
end;
解决方案 »
- 问个跟信誉分有关的问题。
- 如何将数据库中只有年月的记录输出成年月日的格式?
- delphi可以开发这种软件吗
- 我只有两百多行,5列的表格,不像用数据库存储,该怎么办?
- 如何将调用c写的dll得到的char[256]转化成deiphi的string?
- delphi获得网页内容
- 用findfirst 和 findnext怎么样区分文件和目录?
- 用什么函数可在在程序中发送一条消息给Windows主机?
- richedit的问题,急,请帮帮我.
- 解决了全部分数送上,谢,idhttp上传的文件名最多是41个字符,请问这是怎么回事?
- 怎样用代码读取局域网中的所有数据库服务器名??????
- 字符串与字符数组的不同点
var i:Integer;
S:String;
D:WideChar;
ResultW:WideString;
begin
for i:=1 to Round(Length(Src)/4) do begin
S:=Copy(Src,(i-1)*4+1,4);
D:=WideChar(StrToInt('$'+s)); //此处是重点,用delphi提供的widechar可以转换
ResultW:=ResultW+D;
end;
Result:=ResultW;
end;
var
i,j:Integer;
CharTotal:Integer;
CharUnicode:Integer;
begin
Result:='';
try
CharTotal:=StrToInt('$'+Copy(UDInfo,1,2));
if CharTotal mod 2<>0 then
CharTotal:=CharTotal div 2 +1
else
CharTotal:=CharTotal div 2;
except
Exit;
end;
j:=3;
for i:=1 to CharTotal do
begin
try
CharUnicode:=StrToInt('$'+Copy(UDInfo,j,4));
Result:=Result+WideChr(CharUnicode);
Inc(j,4);
except
Exit;
end;
end;
end;