본문 바로가기
Application/Delphi Lecture

UTF-8을 WideString로

by 현이빈이 2008. 8. 13.
반응형
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;
반응형