function StringToWidestring(Source:string):WideString;
var
Len : Integer;
begin
Len := MultiByteToWideChar(936,0,PChar(Source),Length(Source),nil,0);
SetLength(Result,Len);
MultiByteToWideChar(936,0,PChar(Source),Length(Source),PWideChar(Result),Len);//936为简体中文页码
end;
//widestring转成string
function WidestringToString(source:WideString):string;
var
Len : Integer;
begin
Len := WideCharToMultiByte(936,0,PWideChar(source),-1,nil,0,nil,nil);
SetLength(Result,Len-1);
WideCharToMultiByte(936,0,PWideChar(source),Length(source),PChar(Result),Len-1,nil,nil);
end;
本文提供了两个实用的函数,用于实现字符串(string)与宽字符串(WideString)之间的相互转换。这些函数对于需要处理不同字符集编码的应用程序特别有用,尤其是在简体中文环境下。

2679

被折叠的 条评论
为什么被折叠?



