在字符串中查找指定的字符串,并分析该值,如下两个串:
找到"84"后第二位的值,如果都为"1"则返回true,如有一个不为
"1"则为false00008401abcd0330448401000fit8401 -->3个"84"后的第二位都为"1",返回true
00008400abcd0330448401000fit8401-->第1个"84"后的第二位不为"1",返回false
请帮忙写个函数

解决方案 »

  1.   


    function Find84(s: string): boolean;
    var
      i: integer;
    begin
      result := true;
      i := pos('84', s);
      while i > 0 do
      begin
        if i < length(s) - 1 then
        begin
          s := copy(s, i + 3, length(s) - 2-i);
          result := result and (s[1]='1');
        end;
        i := pos('84', s);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      s: string;
    begin
      caption:=booltostr(Find84('88441008401'))
    end;
      

  2.   

    用Pos函数得到"84"的位置,假设他返回i,如果i>0说明字符串中包含有你所搜索的子串,然后用i+4来确定你的标志位即可:
    .....
    Result := False;
    i:=Pos('84',S);
    if i>0 then
       if S[i+4]='1' then
          Result := True
       else
          Result := False;
      

  3.   

    function Check(src, tag :String) :Boolean;  //tag is '84'
    var
      p :Integer;
      s :String;
    begin
      s := '0';
      p := Pos(tag, src);
      while (p > 0) do
      begin
        s := Copy(src, p+2, 1);
        if (s != '1') then break;
        src := Copy(src, p, length(src)-p);
        p := Pos(tag, src);
      end;  Result := (s = '1');
    end;
      

  4.   

    sorry
        s := Copy(src, p+length(tag)+1, 1);  //
        if (s <> '1') then break;            //
        src := Copy(src, p+length(tag)+1, length(src)-p-length(tag)-1);  //