搜索GB2BIG5吧,应该能找到一堆。
解决方案 »
- 求救,怎么在SQL数据库"字段"中追加数据,但不覆盖原有数据!
- 拨号等待返回结果的时间较长,如何才能得到相应的返回值(CPort为CPort控件)
- 如何发送邮件呀?????
- 提供DELPHI好书一本,要的请跟贴
- 寻求控件下载
- 关于AnsiString和WideString的使用
- 两天了还是搞不定,Writeprint() 这个API函数如何用?
- 这里有谁做过点对点的局域网音视频传输/回放?最简单的方案是什么?
- 如何将一个string存到一个文本文件中?
- 如何在IE浏览器的右键菜单中加入自己的菜单项?并且要作出响应。
- 请问高手怎么才能隐藏dos窗口呢?谢谢啦!
- 班竹:我的一个帖子:关于ClientDataSet SQL动态参数的问题?(zengyixun)很有意思的请帮我一下!谢谢!
BIG5TOGB
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;