16,742
社区成员
发帖
与我相关
我的任务
分享
function GetAnsiEncodingAsGB2312(const S: AnsiString): AnsiString;
var
i, l : Integer;
p : PAnsiChar;
begin
p := Pointer(S);
i := 0;
l := Length(s);
while(i<l)do
case p[i] of
#$01..#$7f : { ASCII }
begin
Result := Format('%s%.2x ', [Result, Byte(p[i])]);
Inc(i);
end;
#$A1..#$AF { 非汉字区与非汉字保留区 },
#$B0..#$F7 { 汉字区 },
#$F8..#$FE { 汉字保留区 }:
begin { 这里就不检查低位在不在GB2312编码区了 }
Result := Format('%s%.4x ', [Result, MakeWord(Byte(p[i+1]), Byte(p[i])) ]);
Inc(i, 2);
end;
else { 这里假设其它不在GB2312编码区的文字也是2字节编码,并在后面加个'?'标识一下 }
begin
Result := Format('%s%.4x? ', [Result, MakeWord(Byte(p[i+1]), Byte(p[i])) ]);
Inc(i, 2);
end;
end;
end;