memo1.text中有多串类似这样的字符串(问号为通配符)
"???abc123???"(含引号)
我用如下方法来提取第一个字符串,请教更好的方法,还有如何提取所有的这样的字符串呢。Function TForm1.GetFileName(s:string):string;
var
  posb,pose:integer;
begin
  if pos('abc123',memo1.text)<>0 then
  begin
  posb:=pos(abc123',s);
  pose:=posb;
  repeat dec(posb) until s[posb]='"';
  repeat inc(pose) until s[pose]='"';
  GetFileName:=copy(memo1.text,posb+1,pose-posb-1);
  end;
end;

解决方案 »

  1.   

    先取出所有引号里面的字符串,再将不含abc123的串删掉就可以了,代码如下,结果显示在Memo2中
    procedure TForm1.Button1Click(Sender: TObject);
    var
      s: String;
      Strs: TStrings;
      i, n: Integer;
    begin
      Memo2.Lines.Clear;
      s := Memo1.Lines.Text;
      Strs := TStringList.Create;
      try
        while True do
        begin
          n := Pos('"', s);
          if n = 0 then
            Break;
          Delete(s, 1, n - 1);
          n := PosEx('"', s, 2);
          if n = 0 then
            Break;
          Strs.Add(Copy(s, 1, n));
          Delete(s, 1, n);
        end;
        for i := Strs.Count - 1 downto 0 do
          if Pos('abc123', Strs[i]) = 0 then
            Strs.Delete(i);
        Memo2.Lines.AddStrings(Strs);
      finally
        Strs.Free;
      end;//end of try
    end;
      

  2.   

    http://www.shijinbo.com.cn/viewthread.php?tid=17&extra=page%3D1 
    上面的这篇文章对你会又帮助,它是采集网页,上的一些数据!