我做了一个转换内码的DLL,但感觉不爽,要用码表的转换,所以想直接用程序转换,我想这也不难吧?
解决方案 »
- 高分请教:如何让Label中部分字体显示不同样式
- 如何判断TEdit中输入的内容是大写和小写的混合?
- 哪位大侠用过TRzGroup请进来看看,谢谢!
- 欢迎大家加盟QQ群:Delphi高手突破(群号:1463857) 共同讨Delphi技术,共同交流,共同进步!
- 能否在一台机器上实现三层结构的应用阿,怎么实现?帮忙解决!谢谢!新手!!
- 大侠救命!急需一程序解析器,回者必酬!!
- 有什么好办法判断当前记录是否是记录集中最后一条记录?
- 如何通过编程在outlook express的工具栏上添加一个按钮?
- 请问Delphi6的工具条是用Toolbar控件做的吗,那个竖的分界线是怎么得到的
- 谁知道怎么退出excel?
- 怎样获取局域网内所有机器的名字及IP地址?
- 用Tedit动态生成的多个Edit控件,如何调用Align排列整齐(或其它方法).
[email protected]
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public { Public declarations }
end;var
Form1: TForm1;
function GBtoBIG5(value: string): string;
function BIG5toGB(value: string): string;implementation{$R *.DFM}
var
BIG5Order: array[0..14757] of Word;
GBOrder : array[0..8177] of Word;function GBOffset(value: string): integer;
begin
if length(value) >= 2 then
Result := (Ord(value[1]) - 161) * 94 + (Ord(value[2]) - 161)
else
Result := -1;
end;function BIG5Offset(value: string): integer;
begin
Result := -1;
if length(value) >= 2 then
begin
if (Ord(value[2]) >= 64) and (Ord(value[2]) <= 126) then
Result := (Ord(value[1]) - 161) * 157 + (Ord(value[2]) - 64);
if (Ord(value[2]) >= 161) and (Ord(value[2]) <= 254) then
Result := (Ord(value[1]) - 161) * 157 + 63 + (Ord(value[2]) - 161);
end
end;function WordToString(value: Word): string;
begin
Result := Chr(Hi(value)) + Chr(Lo(Value));
end;function isBIG5(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1] < #161) then
Result := false
else
if ((value[2] >= #64) and (value[2] <= #126)) or ((value[2] >= #161) and (value[2] <= #254)) then
Result := true
else
Result := false
end
else
Result := false
end;function isGB(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1] <= #161) and (value[1] >= #247) then
Result := false
else
if (value[2] <= #161) and (value[2] >= #254) then
Result := false
else
Result := true
end
else
Result := true;
end;function GBtoBIG5(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
Offset : integer;
output : string;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isGB(tmpStr) then
begin
offset:=GBOffset(tmpStr);
if (offset >= 0) and (offset <= 8177) then
begin
output := output + WordToString(GBOrder[offset]);
inc(idx);
end
else
output := output + value[idx] ;
end
else
output := output + value[idx] ; inc(idx, 1);
end;
Result := output;
end;function BIG5toGB(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
output : string;
offset : integer;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isBIG5(tmpStr) then
begin
offset:=BIG5Offset(tmpStr);
if (offset >= 0) and (offset <= 14757) then
begin
output := output + WordToString(BIG5Order[offset]);
inc(idx);
end
else
output := output + value[idx];
end
else
output := output + value[idx]; inc(idx);
end;
Result := output;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:=big5togb(edit1.text);
end;end.
// ver 1.01
unit CVCode;interface
function GBtoBIG5(value: string): string;
function BIG5toGB(value: string): string;implementationvar
BIG5Order: array[0..14757] of Word;
GBOrder : array[0..8177] of Word;function GBOffset(value: string): integer;
begin
if length(value) >= 2 then
Result := (Ord(value[1]) - 161) * 94 + (Ord(value[2]) - 161)
else
Result := -1;
end;function BIG5Offset(value: string): integer;
begin
Result := -1;
if length(value) >= 2 then
begin
if (Ord(value[2]) >= 64) and (Ord(value[2]) <= 126) then
Result := (Ord(value[1]) - 161) * 157 + (Ord(value[2]) - 64);
if (Ord(value[2]) >= 161) and (Ord(value[2]) <= 254) then
Result := (Ord(value[1]) - 161) * 157 + 63 + (Ord(value[2]) - 161);
end
end;function WordToString(value: Word): string;
begin
Result := Chr(Hi(value)) + Chr(Lo(Value));
end;function isBIG5(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1] < #161) then
Result := false
else
if ((value[2] >= #64) and (value[2] <= #126)) or ((value[2] >= #161) and (value[2] <= #254)) then
Result := true
else
Result := false
end
else
Result := false
end;function isGB(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1] <= #161) and (value[1] >= #247) then
Result := false
else
if (value[2] <= #161) and (value[2] >= #254) then
Result := false
else
Result := true
end
else
Result := true;
end;function GBtoBIG5(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
Offset : integer;
output : string;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isGB(tmpStr) then
begin
offset:=GBOffset(tmpStr);
if (offset >= 0) and (offset <= 8177) then
begin
output := output + WordToString(GBOrder[offset]);
inc(idx);
end
else
output := output + value[idx] ;
end
else
output := output + value[idx] ; inc(idx, 1);
end;
Result := output;
end;function BIG5toGB(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
output : string;
offset : integer;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isBIG5(tmpStr) then
begin
offset:=BIG5Offset(tmpStr);
if (offset >= 0) and (offset <= 14757) then
begin
output := output + WordToString(BIG5Order[offset]);
inc(idx);
end
else
output := output + value[idx];
end
else
output := output + value[idx]; inc(idx);
end;
Result := output;
end;initialization BIG5Order[0] := $2020;
BIG5Order[1] := $A3AC;
BIG5Order[2] := $A1A2;
BIG5Order[3] := $A1A3;
BIG5Order[4] := $2020;
.......
GBOrder[8168] := $F876;
GBOrder[8169] := $C566;
GBOrder[8170] := $EFB4;
GBOrder[8171] := $C35E;
GBOrder[8172] := $C4D3;
GBOrder[8173] := $C5C4;
GBOrder[8174] := $F87B;
GBOrder[8175] := $ECB8;
GBOrder[8176] := $C24D;
GBOrder[8177] := $2020;
GBOrder[8177] := $2020;
end.