有两个字符串:
字符串1:'001'
字符串2:'001+002+003+004'
请问Delphi里怎么判断字串1是否在字串2里呢?有这样的函数吗?要求返回值是布尔型的

解决方案 »

  1.   

    if (pos(s2,s2)=0) then haha
      

  2.   

    用pos命 令是可以的 当然也可以用数据结构中的一个算法来实现,不过很难理解1
      

  3.   

    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.
      

  4.   

    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.
      

  5.   

    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;
      

  6.   

    我查了一下,Delphi本身没有你所要求的函数,但你可以用Pos函数来新编一个函数,如下:
    function InStr(SubStr,Str:String):Boolean;
    begin
      if Pos(SubStr,Str)>0 then
        Result:=true  //包含子串
      else
        Result:=False;//不包含子串
    end;
      

  7.   

    if pos(s2,s1)>0 then ShowMessage('包含')