반응형
function UTF8ToWideString(SourceBuf:String): WideString;
var
DestBuf : WideString;
PSourceBuf : PChar;
OutLength : Integer;
begin
GetMem ( PSourceBuf, Length(SourceBuf) );
try
StrPCopy( PSourceBuf, SourceBuf );
OutLength := MultiByteToWideChar(CP_UTF8, 0, PSourceBuf, -1, nil, 0);
SetLength(DestBuf, OutLength);
MultiByteToWideChar(CP_UTF8, 0, PSourceBuf, -1, PWideChar(DestBuf), OutLength);
Result := DestBuf;
finally
FreeMem ( PSourceBuf )
end;
end;
var
DestBuf : WideString;
PSourceBuf : PChar;
OutLength : Integer;
begin
GetMem ( PSourceBuf, Length(SourceBuf) );
try
StrPCopy( PSourceBuf, SourceBuf );
OutLength := MultiByteToWideChar(CP_UTF8, 0, PSourceBuf, -1, nil, 0);
SetLength(DestBuf, OutLength);
MultiByteToWideChar(CP_UTF8, 0, PSourceBuf, -1, PWideChar(DestBuf), OutLength);
Result := DestBuf;
finally
FreeMem ( PSourceBuf )
end;
end;
반응형