举例:
字符串A是 a/b/c/d/e/f字符串B是 a/c/f
字符串C是 b/e
字符串D是 b/g/c怎么用Delphi判断:字符串B包含于A内,字符串C也是包含于A内,字符串D不包含在A内呢?最好有个代码供我研究,多谢大家啦!

解决方案 »

  1.   

    用循环判断把 简单例子.   B 包含在A中.
    function funcA(A, B: string): Boolean;
    var
      i:Integer;
      AList: TStringList;
    begin
      Result := True;
      AList := TStringList.Create;
      AList.Delimiter := '/';
      AList.DelimitedText := B;
      for i := 0 to AList.Count - 1 do
      beign
        Result := pos(AList[I], A) > 0;
        if not Result then Break;
      end;   
    end;
      

  2.   

    function Contains(const Str, SubStr: string): Boolean;
    var
      P1, P2: PChar;
    begin
      P1 := PChar(SubStr);
      while P1^ <> #0 do
      begin
        P2 := PChar(Str);
        while P2^ <> #0 do
        begin
          if P2^ = P1^ then
            Break;
          Inc(P2)
        end;
        if P2^ = #0 then
        begin
          Result := False;
          Exit
        end;
        Inc(P1);
      end;
      Result := True
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     if Contains('a/b/c/d/e/f', 'b/c') then
       ShowMessage('')
    end;
      

  3.   

    一楼的代码改进一下就可以了
    function funcA(A, B: string): Boolean;
    var
      i:Integer;
      AList: TStringList;
    begin
      Result := True;
      AList := TStringList.Create;
      AList.Delimiter := '/';
      AList.DelimitedText := B;
      for i := 0 to AList.Count - 1 do
      begin
      Result := pos(AList[I], A) > 0;
      if not Result then Break
      else A:=copy(A,pos(AList[I], A)+1,length(A)-pos(AList[I], A));  //比如:该字符串a/c/c/d是不在字符串A中的,是吧?
      end;   
    end;