62,614
社区成员
发帖
与我相关
我的任务
分享
var buf 保存的是接收到的byte数据
function DecodeUTF8(var buf:array of Byte;StartPosition,Len:Integer):string;
var
i:Integer;
m:String;
begin
m:='';
FOR i:=0 TO len-1 DO
m:=m+chr(buf[i+StartPosition+1]);
Result:=UTF8Decode(m);
end;
function Utf8Decode(const S: UTF8String): WideString;
var
L: Integer;
Temp: WideString;
begin
Result := '';
if S = '' then Exit;
SetLength(Temp, Length(S));
L := Utf8ToUnicode(PWideChar(Temp), Length(Temp)+1, PChar(S), Length(S));
if L > 0 then
SetLength(Temp, L-1)
else
Temp := '';
Result := Temp;
end;