先生成一个所有的简体汉字字符表,然后用Word的转换功能 将其转换成对应的繁体字表,再查表就可以. procedure TForm1.Button1Click(Sender: TObject); var codefile:File of Byte; i,j:Integer; W:Array [0..1] of Byte; begin AssignFile(codefile,'table2.txt'); ReWrite(CodeFile);//生成简体表 for i:=$80 to $FF do for j:=$80 to $FF do begin W[0]:=i; W[1]:=j; BlockWrite(codeFile,W,2); end; CloseFile(codefile); end;//用Word将table2.txt转换成table.txt后再运行下面代码 procedure TForm1.Button2Click(Sender: TObject); var i,j:Integer; W:Array [0..1] of Char; codefile:File of Byte; begin Edit2.Clear; AssignFile(codefile,'table.txt'); ReSet(CodeFile); for i:=1 to Length(Edit1.Text) do if i mod 2=0 then begin j:=((Ord(Edit1.Text[i-1])-$80)*$80+(Ord(Edit1.Text[i])-$80))*2; Seek(CodeFile,j);//查表 BlockRead(CodeFile,W,2); Edit2.Text:=Edit2.Text+W[0]+W[1];//生成繁体字 end; CloseFile(codefile); end;//摘自大富翁离线包
http://delphi.ktop.com.tw/topic.asp?TOPIC_ID=328951, 2. 可以,把 MultiByteToWideChar 的第一個參數傳入 936,就可以把 GB 碼轉成Unicode3. 如果只考慮轉碼,不考慮繁簡寫法不同的話,可以用下列程式 function Big5ToGB(sBig5: string): string; var ws: array[0..32767] of WideChar; s: array[0..65535] of char; begin ZeroMemory(@ws, Length(ws) * SizeOf(WideChar)); ZeroMemory(@s, Length(s) * SizeOf(char)); MultiByteToWideChar(950, MB_COMPOSITE, PChar(sBig5), -1, @ws, Length(ws)); WideCharToMultiByte(936, WC_COMPOSITECHECK, @ws, -1, @s, Length(s), '?', PBOOL(false)); result := s; end; 若要達到轉換後轉繁簡寫法不同的話,以上程式不適用 4. WideCharToMultiByte,第一個參數傳入 936
将其转换成对应的繁体字表,再查表就可以.
procedure TForm1.Button1Click(Sender: TObject);
var
codefile:File of Byte;
i,j:Integer;
W:Array [0..1] of Byte;
begin
AssignFile(codefile,'table2.txt');
ReWrite(CodeFile);//生成简体表
for i:=$80 to $FF do
for j:=$80 to $FF do begin
W[0]:=i; W[1]:=j;
BlockWrite(codeFile,W,2);
end;
CloseFile(codefile);
end;//用Word将table2.txt转换成table.txt后再运行下面代码
procedure TForm1.Button2Click(Sender: TObject);
var
i,j:Integer;
W:Array [0..1] of Char;
codefile:File of Byte;
begin
Edit2.Clear;
AssignFile(codefile,'table.txt');
ReSet(CodeFile);
for i:=1 to Length(Edit1.Text) do
if i mod 2=0 then begin
j:=((Ord(Edit1.Text[i-1])-$80)*$80+(Ord(Edit1.Text[i])-$80))*2;
Seek(CodeFile,j);//查表
BlockRead(CodeFile,W,2);
Edit2.Text:=Edit2.Text+W[0]+W[1];//生成繁体字
end;
CloseFile(codefile);
end;//摘自大富翁离线包
function Big5ToGB(sBig5: string): string;
var ws: array[0..32767] of WideChar;
s: array[0..65535] of char;
begin
ZeroMemory(@ws, Length(ws) * SizeOf(WideChar));
ZeroMemory(@s, Length(s) * SizeOf(char));
MultiByteToWideChar(950, MB_COMPOSITE, PChar(sBig5), -1, @ws, Length(ws));
WideCharToMultiByte(936, WC_COMPOSITECHECK, @ws, -1, @s, Length(s), '?', PBOOL(false));
result := s;
end;
若要達到轉換後轉繁簡寫法不同的話,以上程式不適用
4. WideCharToMultiByte,第一個參數傳入 936