在做跟手机短信相关的东东时候常遇到各种编码格式数据的转换,特写了几个函数,供参考。
function EncodeEnglish(var s:string):string;
var
i,j,len:Integer;
cur:Integer;
t:String;
begin
Result:='';
len:=Length(s);
//j 用于移位计数
i:=1;j:=0;
while i<=len do
begin
if i<len then
//数据变换
cur:=(ord(s[i]) shr j) or ((ord(s[i+1]) shl (7-j)) and $ff)
else
cur:=(ord(s[i]) shr j) and $7f;
FmtStr(t,'%2.2X',[cur]);
Result:=Result+t;
inc(i);
//移位计数达到7位的特别处理
j:=(j+1) mod 7;
if j=0 then inc(i);
end;
end;
//end;
function BinaryUniCode2Gb2312(ABinaryString:PChar;APosStart,APosEnd:integer):string;
var
i,iLen:integer;
AscHexText,TmpHexStr:string;
AsciiInt:integer ;
AscLen,AscUniLen:integer;