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;
用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;
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;
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); //
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;
.....
Result := False;
i:=Pos('84',S);
if i>0 then
if S[i+4]='1' then
Result := True
else
Result := False;
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;
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); //