Decode UTF8 String Function in Delphi/Pascal



function DecodeUtf8Str(const S: UTF8String): WideString;
var lenSrc, lenDst : Integer;
begin
lenSrc := Length(S);
if(lenSrc=0)then Exit;
lenDst := MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, nil, 0);
SetLength(Result, lenDst);
MultiByteToWideChar(CP_UTF8, 0, Pointer(S), lenSrc, Pointer(Result), lenDst);
end;

Comments

Jesse Lau · @jesselaunz

Let's connect

Long-form on the blog, videos on YouTube, daily notes on 𝕏 — one person, one thread.