如何在字符串数组中查找字符串

解决方案 »

  1.   

    s:array[1..10] of string;
    begin
     for i:= 1 to 10 do
     begin
       pos('',s[i]);
     end;
    end;
      

  2.   

    你可以使用TStrings类,
    如:
    var
     sNames:TStrings;
     iIndex:integer; 
    begin
      sNames:=TStringList.Create;
      sNames.add('张三');
      sNames.add('李四');
      sNames.add('王五');
      iIndex:=sNames.IndexOf('李四');
      //如果iIndex>-1 则说明找到,否则就没有找到。
      //你也可以简单的这样用sNames[0]...
    end;
      

  3.   

    //寻找与目标字符串最匹配的字符串
    function MaxMatchStr(DestStr:String;Strs:array of String):String;
    var
      I:Integer;
    begin
      Result:='';
      for I:=1 to Length(Strs) do
        //如果与目标匹配
        if (Pos(Strs[I],DestStr)>0) and
        //而且比现在找到的结果更长
           (Length(Strs[I])>Length(Result)) then
        //替换当前结果
          Result:=Strs[I];
    end;
      

  4.   

    //字符串匹配函数
    function MatchToken(var Buffer: Pchar; const MatchStr: string): Boolean;
    var
      Token: Pchar;
    begin
      Token := Pchar(MatchStr);
      while Buffer^ <> #0 do
      begin
        if UpCase(Buffer^) = Token^ then
          inc(Token)
        else if Token <> Pchar(MatchStr) then
        begin
          Token := Pchar(MatchStr);
          if UpCase(Buffer^) = Token^ then
            inc(Token);
        end;
        inc(Buffer);
        if Token^ = #0 then
          Break;
      end;
      Result := Token^ = #0;
    end;
      

  5.   

    var x:TStrings;
        i:integer;
    begin
    x:=TStringList.Create;//这就是字符串数组
    x.add('abc');
    x.Add('bcd');
    x.Add('cde');
    x.Add('def');
    for i:=low(x) to high(x) do
    begin
    if pos('ab',x[i])>0 then//假定ab是要寻找的字符串
     showmessage('success') 
    else showmessage('fail');
    end;
      

  6.   

    跟搜索算法一样,好象delphi有样例。
      

  7.   

    把careerist() 的稍修改一下,最简单:
    s:array of string;
    begin
     for i:= Low(s) to High(s) do
     begin
       If pos('字符',s[i-1])>0 Then ShowMessage('找到');
     end;
    end;