做了一个局域网内的QQ,不过当简体操作系统与繁体操作系统通讯时出现乱码。
我想在接收信息时作一个检测:
当信息为GB时,转换为BIG5码?
请大家指点,谢了
我想在接收信息时作一个检测:
当信息为GB时,转换为BIG5码?
请大家指点,谢了
解决方案 »
- delphi图像处理 对比度测试 过程?
- 请教Delphi怎么捕获游戏手柄的消息
- 字符串查找问题
- 有谁比较熟悉WOSA/XFS啊?(送100分啊)
- {$IFDEF VCL70_OR_HIGHER} ParentBackground := False;{$ENDIF}這段 代碼是什麼意思??
- IncUpdate中文版发布,10分钟不写代码做智能升级
- 再次求助:为什么图片信息会丢失?
- 用d6编译的问题!高分求解。
- 数据库的问题!!在数据库中查找到一条需要的数据,取完数据后,我想回到当前的位置,好象应该用到游标,书签之类的,可我不会!!!
- Delphi 有没有象C一样的断言(ASSERT)?
- 谁知道Installshield Express 3.53的激活码???
- 如何在delphi程序中实现数据回滚!
BIG5->GBK 不会丢字,GBK饱含了全部的BIG5汉字,但是编码不同了。
function BIG5toGB_NonAPI(value: string): string;
function isGB(value: string): Boolean;
function isBIG5(value: string): Boolean;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_NonAPI(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_NonAPI(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;