网页中有 offerdetail/64314373.html……offerdetail/122811374.html……offerdetail/181000958.html……
这样的信息。其中 64314373  122811374  181000958 这些数字信息对我是有用的。
我现在已经把网页内容读入字符串 s 中了。怎样把这些数字信息取出来呢 ?这些数字 位数是不一样的,有的8位数,有的9位
唯一的相同点就是他们都处于字符串‘offerdetail/’和‘.html’之间。拜托了。

解决方案 »

  1.   


    var
      i,j,L: integer;
      ArrayStr: array of string;
    begin
      i := pos(s,'offerdetail/');  //返回第一组<offerdetail/>的位置
      j := pos(s,'.html');         //返回第一组<.html>的位置
      while i>0 do
      begin
        L:=length(ArrayStr);
        SetLength(ArrayStr,L+1);
        ArrayStr[L] := copy(S,i+12,j-i-12);
        delete(S,j,5);     //删除第一组<.html>
        delete(S,i,12);    //删除第一组<offerdetail/>    i := pos(s,'offerdetail/');
        j := pos(s,'.html');
      end;
    end;结果是:把所有的数字信息存储在ArrayStr数组里
      

  2.   

    I'm sorry. 以上的pos语句写错了。应该是 i := pos('offerdetail/',s);   依次类推。 pascal生疏了。
      

  3.   

    给你个思路吧:
    先pos('offerdetail/',s),将之前的字符删除,再copy(s,0,pos('.html',s))存到数组中,再删除,以此类推一个while循环即可。
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      s,sTemp:string;
    begin
      s:='offerdetail/64314373.html¡­¡­offerdetail/122811374.html¡­¡­offerdetail/181000958.html¡­¡­';
      while pos('offerdetail/',s)>0 do
      begin
        delete(s,1,pos('offerdetail/',s)+11);
        sTemp:=copy(s,1,pos('.html',s)-1);
        ListBox.Items.Add(sTemp);
      end;
    end;
    测试可用,其实我觉得最简单的应该是用正则表达式来做哈...
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      s,sResult:string;
    begin
      s:='offerdetail/64314373.html……offerdetail/122811374.html……offerdetail/181000958.html……';
      sResult:='';
      i:=0;
      while pos('offerdetail/',s)>0 do
      begin
        delete(s,1,pos('offerdetail/',s)+11);
        sResult:=sResult+copy(s,1,pos('.html',s)-1)+',';
        i:=i+1;
      end;
      ShowMessage(sResult);
    end;
    要不这样也可以,输出一个符合要求的字符串,用逗号分开...