Delphi 文字查詢函式(一)
阿新 • • 發佈:2018-11-23
一:function Pos(Substr: string; S: string): Integer;
註解:該函式是查詢元素第一次出現的位置。
1.... 框圖:
2 .....程式碼:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var str1,word:string; i,j:integer; begin str1:='dsf4654f6<ds>ad<<<' ; word:=Edit1.Text; j:=pos(word,str1);//在字串str1中查詢"<" if j<>0 then //得到的j是字串中出現的位置,是整型 showmessage('<'+'在第'+inttostr(j)+'個位置'); //第十個位置 end; end.
3....執行結果: