一: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....运行结果: