比如:a123bc和123,于是能找到,并且返回第一次出现123的位置,我不想使用pos函数,想自己写一下,能帮我一下吗,如何处理?
----------------------------------------------
ignore,Ctrl+Alt+Del,then begin;is die,but just not die。
var ss,si: string; i,j,a:integer; begin a:=0; ss:='a1234b'; si:='1234'; for i:=0 to length(ss)-1 do begin for j:=0 to length(si)-1 do begin if (ss[i+j]<>si[j]) then break else if j=(length(si)-1) then //如果j已于长度减1相等,说明已经比较完si了 a:=i; //将ss中开始位置i赋值给a end; end; Edit1.Text := inttostr(a); end;
end.
这是我的程序,但是a总是返回0,我想哪里错了,但是又不知道错在那里,能不能帮我改一下啊,谢谢了。。。。。。。。。。。。。。。。。。。。。
----------------------------------------------
ignore,Ctrl+Alt+Del,then begin;is die,but just not die。
那请问我的程序不知道写的对不对??? to 阿贡:不过可能翻译过来语法要改动。。。。。。。 还有咯,为什莫一定要从索引1开始??
----------------------------------------------
ignore,Ctrl+Alt+Del,then begin;is die,but just not die。
procedure TForm1.Button1Click(Sender: TObject); var ss, si: string; i, j, a, s: integer; OK: bool; begin a := 0; ss := 'a1234b'; si := '1234'; for i := 1 to length(ss) do begin if ss[i] = si[1] then begin OK := false; s := i; for j := 1 to length(si) do begin if si[j] <> ss[s] then begin OK := true; break; end; inc(s); end; if(not OK) then a := i; end; end; button1.Caption := inttostr(a);
to 阿贡:我刚学delphi,不明白您的意思,字符串第0个位置是标志位是什莫意思??? 那末例如:TListBox.Items[0],他的索引也从0开始,不是表示的是第一行的字符串?
----------------------------------------------
ignore,Ctrl+Alt+Del,then begin;is die,but just not die。
您说的字符串指的ansistring,shortstring,widestring等所有这些字符串类型吗? 如果我想使用标志位的话,有什麽用呢?
----------------------------------------------
ignore,Ctrl+Alt+Del,then begin;is die,but just not die。