请教各位高手,中英文混合的字符串应该如何进行PDU编码??? (100分)

R

rgb2000

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位高手,中英文混合的字符串应该如何进行PDU编码???
思路是什么?[:(!][?]
 
AT+CMGF=1 选择PDU编码,0为文本模式
AT+CMGL=0 列出SIM卡中短消息,0-未读,1-已读,2-待发,3-已发
AT+CMGR=1 读取指定编号的短消息
AT+CMGD=1 删除短消息
AT+CMGS="13958138454" 发送短消息,CTRL+Z结束
>Good Morning! ^Z
先判断字符类型:
function Test(Str: string): Boolean;
var
i: Integer;
begin
Result := False;
if ord(Str) > $7F then
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:char;
j:integer;
s:string;
begin
i:='4';//这个为初始阶段
s:=edit1.text;
for j:=1 to length(s) do
begin
if test[j] then
begin
if (i='4')or(i='0')then
begin
i:=0;//这个为中文
inc(j);
end
else
begin
i:='2';//这个为中英文混合
end;
end
else
begin
if (i='4')or(i='1')then
begin
i:=2;//这个为中英文混合
inc(j);
end
else
begin
i:='1';//这个为英文
end;
end;
end;
if i='0' then
showmessage("这个为中文")
else
if i='1' then
showmessage("这个为英文")
else
showmessage("这个为中英文混合")
end;

PDU英文编码:
function EncodeEnglish(var s:String): String;
var
i,j, Cur: Integer;
t:String;
begin

Result := '';
i := 1;
j := 0;

while i <= Length(s) do

begin

if i < Length(s) then

Cur := (ord(s) shr j) or ((ord(s[i+1]) shl (7-j)) and $ff)
else

Cur:=(ord(s) shr j) and $7f;
FmtStr(t,‘%2.2X’,[cur]);
Result := Result + t;
inc(i);
j := (j+1) mod 7;
if j = 0 then

inc(i);
end;

end;
 
 
中文编码:
function EncodeChinese(var s:WideString): String;

var
i, Cur: Integer;
t: String;
begin

Result := '';
i := 1;
while i <= Length(s) do

begin

Cur:=ord(s);
FmtStr(t,'%4.4X',[Cur]);

Result := Result + t;
inc(i);
end;

end;

 
你只给出了中文和英文的PDU编码方式,如果是中英文混合,是否是中文时调用中文编码函数,英文时调用英文编码函数,然后组合起来呢?我昨天试了试收到的是乱码,是我的方法不对吗?
 
多人接受答案了。
 
顶部