操作字符串,求两个相反的函数。
1、缺省的GSM 字符集为7位编码,可以简单地理解为ASCII码(ASCII值小于80Hex,因此,Bit8被忽略),依次将下一7位编码的后几位逐次移至前面,形成新的8位编码,参见表2箭头指示。需要注意的是第9行,移位计数已达7位,则直接将本编码前加0。
function Encode1(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;
2、通过Delphi的WideString类型转换,可以巧妙地实现GB2312到Unicode的编码转换
function TForm1.EncodeCn(s: WideString): string;
var
i, len: Integer;
cur: Integer;
t: string;
begin
Result := '';
len := Length(s);
i := 1;
while i <= len do
begin
cur := ord(s[i]);
FmtStr(t, '%4.4X', [cur]);
Result := Result + t;
inc(i);
end;
end;
我现在想求两个相反的函数。