写一个函数,函数接收的参数是(pStr, pStr_begin, pStr_end),函数输出是一个数组,该数组包含了pStr字符串中所有位于字符串pStr_begin和字符串pStr_end间的字符串。比如, 参数是 '11AgoodB, AbadBqqqAmanB22', 'A', 'B'应该得到一个包含了 'good', 'bad', 'man' 的数组.

解决方案 »

  1.   


    做个参考
    procedure TForm1.split(pStr, pStr_begin, pStr_end: string);
    var
      i:Integer;
      array_A,array_B:array of Integer;
    begin
      for i := 1 to Length(pStr) do
      begin
        if AnsiCompareStr(pStr[i],'A') = 0 then
        begin
          SetLength(array_A,Length(array_A)+1);
          array_A[High(array_A)] := i;
        end
        else if AnsiCompareStr(pStr[i],'B') = 0 then
        begin
          SetLength(array_B,Length(array_B)+1);
          array_B[High(array_B)] := i;
        end;
      end;
    //下面你可以加一个判断,就是'A'和'B'出现次数不配对的情况下,要进行一下处理,下面是认为他们出现次数都一样的情况
      for i := Low(array_A) to High(array_A) do
      begin
        ListBox1.Items.Add(Copy(pStr,array_A[i]+1,array_B[i]-array_A[i]-1));
      end;
    end;
      

  2.   

    A(pStr, pStr_begin, pStr_end);
    var i,j:array[0..100] of integer;
        sStr:array[0..100] of String;
    x,m,n,t:integer;
      begin
      m:=0;
      n:=0;
      t:=0;
     for (x:=1 to length(pStr)) do
       begin
      case pStr[i] of 
     pStr_begin:begin
         i[m]:=x;
          m:=m+1;
         end;
     pStr_end:begin
         j[n]:=x;
          n:=n+1
         end;    //找出A和B在字符串的位置,存到数组i和j中
         end;
    for x:=0 to m do
     begin
     sStr[t]:=copy(pStr,i[x],j[x]);
      t:=t+1;
      end;
      end;       //存入数组sStr中我不知道你说的pStr_begin和pstr_end是不是成对出现的,所以不知道写的对不对。
      

  3.   


    type
       myarray=array of string;Function serch(pStr,pStr_begin,pStr_end:string):myarray;
    var
      i,j,n:integer;
    begin
       n:=0;
       repeat
       i:=pos(pStr_begin,pStr);
       j:=pos(pStr_end,pStr);
       result[n]:=copy(pStr,i+1,j-i-1);
       inc(n);
       delete(pStr,1,j);
      until i=0;
    end;
      

  4.   

    感觉这样比较好Function serch_str(pStr,pStr_begin,pStr_end:string):Tstrings;
    var
      i,j:integer;
    begin
      result:=Tstringlist.Create;
      repeat
       i:=pos(pStr_begin,pStr);
       j:=pos(pStr_end,pStr);
       result.Add(copy(pStr,i+1,j-i-1));
       delete(pStr,1,j);
      until i=0;
    end;