d7 ansi和unicode相互转换

d7 ansi和unicode相互转换

Ansi转Unicode

function AnsiToUnicode(Str: String): WideString;
  var
    LWideChar: PWideChar;
    Len: Integer;
  begin
    Len := (Length(Str) + 1) * 2;
    GetMem(LWideChar, Len);
    ZeroMemory(LWideChar, Len);
 
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(Str), Length(Str), LWideChar, Len);
    Result := LWideChar;
    FreeMem(LWideChar);
  end;

  

Unicode转Ansi
function UnicodeToAnsi(s:WideString):string;
  var
    lpChar:PChar;
    len:integer;
    begin
    len := Length(s) * 2;
    GetMem(lpChar,len);
    ZeroMemory(lpChar, len);
    WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, PWideChar(s),
    Length(s),lpChar,Len, nil, nil );
 
    Result := lpChar;
    FreeMem(lpChar);
  end;

  

d7 ansi和unicode相互转换

上一篇:运维技术-中间件-消息队列-RabbitMQ02


下一篇:前端基础---audio/video音视频标签