本人近期在做多语言包,脚本文件里有很多汉字,我想在读取脚本文件txt时,直接转换成unicode,然后在程序里调用调用处理,哪位高手提供下参考资料,谢谢啦
解决方案 »
- fastreport 3.07 纸张长度调整
- 如何捕获鼠标消息
- 如何解决 Access Violation 问题
- 一个查询的问题
- 救命呀,有关delphi与sql连接的问题---------------------在线等待
- 高分易得,一问难求!(如何实现类似java中eval函数功能)
- ado
- 问个简单的问题,谢了
- 怎样让程序最小化后到状态栏中?************************************************************************
- 用Delphi4编译的控件在Delphi5下不能使用
- 有那们兄弟用过Delphi Scintilla,有的进来看看
- listbox如何实现按行显示?
使用api函数中MultiByteToWidechar function UnicodeEncode(Str:string;CodePage:integer):WideString;
var
Len:integer;
begin
Len:=Length(Str)+1;
SetLength(Result,Len);
Len:=MultiByteToWideChar(CodePage,0,PChar(Str),-1,PWideChar(Result),Len);
SetLength(Result,Len-1); //end is #0
end; function UnicodeDecode(Str:WideString;CodePage:integer):string;
var
Len:integer;
begin
Len:=Length(Str)*2+1; //one for #0
SetLength(Result,Len);
Len:=WideCharToMultiByte(CodePage,0,PWideChar(Str),-1,PChar(Result),Len,nil,nil);
SetLength(Result,Len-1);
end; function Gb2Big5(Str:string):string;
begin
SetLength(Result,Length(Str));
LCMapString(GetUserDefaultLCID,LCMAP_TRADITIONAL_CHINESE,
PChar(Str),Length(Str),
PChar(Result),Length(Result));
Result:=UnicodeDecode(UnicodeEncode(Result,936),950);
end; function Big52Gb(Str:string):string;
begin
Str:=UnicodeDecode(UnicodeEncode(Str,950),936);
SetLength(Result,Length(Str));
LCMapString(GetUserDefaultLCID,LCMAP_SIMPLIFIED_CHINESE,
PChar(Str),Length(Str),
PChar(Result),Length(Result));
end;function Utf8Encode(const WS: WideString): UTF8String;
var
L: Integer;
Temp: UTF8String;
begin
Result := '';
if WS = '' then Exit;
SetLength(Temp, Length(WS) * 3); // SetLength includes space for null terminator
L := UnicodeToUtf8(PChar(Temp), Length(Temp)+1, PWideChar(WS), Length(WS));
if L > 0 then
SetLength(Temp, L-1)
else
Temp := '';
Result := Temp;
end;
var
s:string;
i:integer;
j,k:string[2];
a:array [1..1000] of char;
begin
s:='';
StringToWideChar(Ansi,@(a[1]),500);
i:=1;
while ((a[i]<>#0) or (a[i+1]<>#0)) do
begin
j:=IntToHex(Integer(a[i]),2);
k:=IntToHex(Integer(a[i+1]),2);
s:=s+k+j;
i:=i+2;
end;
Result:=s;
end;function Tmainform.UnicodeToAnsi(Unicode: string):string;
var
s:string;
i:integer;
j,k:string[2]; function ReadHex(AString:string):integer;
begin
Result:=StrToInt('$'+AString);
end;
begin
i:=1;
s:='';
while i<Length(Unicode)+1 do
begin
j:=Copy(Unicode,i+2,2);
k:=Copy(Unicode,i,2);
i:=i+4;
s:=s+Char(ReadHex(j))+Char(ReadHex(k));
end;
if s<>'' then
s:=WideCharToString(PWideChar(s+#0#0#0#0))
else
s:='';
Result:=s;
end;//自己搞定了