function UnicodeToGB(const wsUnicode: WideString): string;
var
iLen: Integer; //需要转换的字符数
sTmp: string;
begin
//计算转换的字符数
iLen := WideCharToMultiByte (936, 0, PWideChar(wsUnicode), -1, nil, 0, nil, nil);
//给sTmp分配内存
SetLength(sTmp, iLen);
ZeroMemory(PChar(sTmp), SizeOf(Char) * iLen);
//转换Unicode码到Gb码,使用API函数WideCharToMultiByte
WideCharToMultiByte(936, WC_COMPOSITECHECK, PWideChar(wsUnicode), -1,
PAnsiChar(sTmp), iLen, '?', PBOOL(False));
Result := PChar(sTmp);
end;
应用举例:
将反向输出字符串
var
strShow:WideString;
strTemp:WideString;
i,len:integer;
begin
strShow:='1345啊sdfdw扶绥地矿局发fsdhjh';
strTemp:=strShow;
len:=Length(strShow);
for i:= 1 to len do
begin
strTemp[i]:=strShow[len + 1 - i];
end;
strTemp:=UnicodeToGB(strTemp);
showmessage(strTemp);