Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.
Returns the index value of the first character in a specified substring that occurs in a given string.UnitSystemCategorystring handling routinesDelphi syntax:function Pos(Substr: string; S: string): Integer;DescriptionIn Delphi, Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.The PosEx function is similar to Pos, but provides additional features and can be used in C++ code.
procedure TForm1.Button1Click(Sender: TObject); Var s1,s2:String; begin s1:='abcdefg'; s2:='bcdf'; if Pos(s2,s1)<>0 then showmessage('yes') else showmessage('No'); end;
我查了一下,Delphi本身没有你所要求的函数,但你可以用Pos函数来新编一个函数,如下: function InStr(SubStr,Str:String):Boolean; begin if Pos(SubStr,Str)>0 then Result:=true //包含子串 else Result:=False;//不包含子串 end;
Var s1,s2:String;
begin
s1:='abcdefg';
s2:='bcdf';
if Pos(s2,s1)<>0 then showmessage('yes') else
showmessage('No');
end;
function InStr(SubStr,Str:String):Boolean;
begin
if Pos(SubStr,Str)>0 then
Result:=true //包含子串
else
Result:=False;//不包含子串
end;