DecodeUtf8Str解决系统自带UTF8解码缺陷
1 function DecodeUtf8Str(const S: UTF8String): WideString;
2 var lenSrc, lenDst : Integer;
3 begin
4 lenSrc := Length(S);
5 if(lenSrc=0)then Exit;
6 lenDst := MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, nil, 0);
7 SetLength(Result, lenDst);
8 MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, Pointer(Result), lenDst);
9 end;
2 var lenSrc, lenDst : Integer;
3 begin
4 lenSrc := Length(S);
5 if(lenSrc=0)then Exit;
6 lenDst := MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, nil, 0);
7 SetLength(Result, lenDst);
8 MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, Pointer(Result), lenDst);
9 end;
因为Delphi自带的转换函数遇到其无法识别的字符串就返回空,以上函数可解决该问题。