一个字符串里包含了四个空格,怎样取第四个空格后的字符串

解决方案 »

  1.   

    for i:=1 to Length(ThisStr) do
    begin
      if ThisStr[i]:=' ' then
      begin
        k:=K+1;
        if K=4 then
        begin
          R:=i;
        end;
      end;
    end;
    TrimedStr:=copy(ThisStr,R,n);
      

  2.   

    i;=pos('4个空格',str)
    str1:=RightStr(str,Legnth(str)-i+1)
      

  3.   

    var
    i: integer;
    p: integer;
    str: string;
    s: string;
    begin
    p := 0
    i := 1;
    repeat
    if str[i]=' ' then
    inc(p);
    inc(i);
    until p=4;

    s := rightstr(str, length(str)-p);
    end;

      

  4.   

    for i:=1 to 4 do 
    begin
      index:=pos(' ',yourStr);
      yourStr[index]:='';
    end;StrYouWanted:=copy(yourStr,index,length(yourStr)-index);
      

  5.   

    copy(str,pos('    ',str)+1,length(str))
      

  6.   

    我刚才没表达清楚,现在补充:
    怎样取第三个到第四个空格之间的字符串
    var
     i,k,m,n:integer;
     str:string;
    begin
    str:=trim(listbox1.Items[0]);
    for i:=1 to Length(str) do
    begin
      if str[i]=' ' then
      begin
        k:=K+1;
        if K=6 then
        begin
           m:=i;
        end;
        if K=8 then
        begin
           n:=i;
        end;
      end;
    end;
    showmessage(copy(listbox1.Items[0],m,n-m));
    为什么这样得到的是整个字符串
    在最后加上以下代码这OK了
    showmessage(inttostr(n));
      

  7.   

    将你的代码改了一下
    var
     i,k,m,n:integer;
     str:string;
    begin
    k:=0;
    str:=trim('123 4 5 6 7 89 999');
    for i:=1 to Length(str) do
    begin
      if str[i]=' ' then
      begin
        k:=K+1;
        if K=3 then m:=i;
        if K=4 then n:=i;
      end;
    end;
    showmessage(copy(str,m,n-m));
      

  8.   

    thirdSpace,fourthSpace;integer;
    for i:=1 to 4 do 
    begin
      index:=pos(' ',yourStr);
      yourStr[index]:='';
      if i=3 then
        thirdSpace:=index;
      if i=4 then
         fourthSpace:=index;
    end;StrYouWanted:=copy(yourStr,thirdSpace,fourthSpace-thirdSpace);