Pos的应用(很不解) ( 积分: 50 )

  • 主题发起人 主题发起人 moroko
  • 开始时间 开始时间
M

moroko

Unregistered / Unconfirmed
GUEST, unregistred user!
pos用过很多次了
今天碰到了一个让我很不解的问题,真的就是晕死
memo1.text的内容为下面的数据
//--------------------------------------------------------------------
AT+CMGL=4

+CMGL: 2,1,,62
0891683108200705F0040D91683174066967F80000709020220140232F482412894422914824128944229148241289442291482412894422914824128944229148241289442201
+CMGL: 3,1,,24
0891683108200705F0040D91683174066967F8000870902022655423044F60597D
+CMGL: 4,1,,68
0891683108200705F02405A11068F00008709030002230233460A8901A8FC77F514E0A84254E1A538567E5770B8BE67EC651855BB976849A8C8BC178014E3AFF1A003100320037003300330036
+CMGL: 5,1,,68
0891683108200705F02405A11068F00008709030105040233460A8901A8FC77F514E0A84254E1A538567E5770B8BE67EC651855BB976849A8C8BC178014E3AFF1A003800310037003100350031
+CMGL: 6,1,,158
0891683108200705F04409A109201107F10004709030809332238C0B05040B8423F00003DF020135061503AE81EAB13231312E3133372E37392E373000AF8202056A0045C60C03676F2E693133392E636E2F707573682F675F6D626F7864662E646F00110334393031323538343036373033313734313631000AC307200709030946260103E38090E696B0E4BFA1E681AFE38091E78EA9E6B8B8E6888F2CE8B58FE5A4A7E78987
+CMGL: 7,1,,74
0891683108200705F04409A109201107F1000470903080933223380B05040B8423F00003DF02022CE7A7BBE58AA8E6A2A6E7BD91E7B2BEE59381E6B8B8E6888FE781ABE783ADE4B88BE8BDBDE4B8AD21000101

OK
//--------------------------------------------------------------------

按照常里说+CMGL:在这里出现的次数是6次
使用下面的showmessage(inttostr(pos('+CMGL',memo1.Text)));
结果是12次
如果showmessage(inttostr(pos('+CMGL: 3,1,,24',memo1.Text)));
按理说结果应该是一 可结果更惊人 174
 
晕,pos是第一次出现该子字符串的位置,
pos(subStr,str);
 
估计是你测试代码有错误,你用下面代码试试:
procedure TForm1.Button1Click(Sender: TObject);
var
p, count: integer;
s,s1: string;
begin
count:=0;
s1:='+CMGL:';
s:=Memo1.Text;
p:=pos(s1, s);
while p>0 do
begin
count:=count+1;
s:=copy(s,p+Length(s1),Length(s)-(p+Length(s1)-1));
p:=pos(s1, s);
end;
showmessage(inttostr(Count));
end;
 
忘了,呵呵
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
625
import
I
后退
顶部