各位高手请指教!如何提取字符串中的部分字符串:
例如提取'33 23 43'(中间为空格) 中的 '33' ,'23' ,'43' 。

解决方案 »

  1.   

    用pos取空格位置,用copy取空格前的字符
      

  2.   

    Copy(S; Index, Count: Integer): string;
    例题
    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);var
      Found: boolean;
      i,SelSt: Integer;
      TmpStr: string;
    begin
      { first, process the keystroke to obtain the current string }
      { This code requires all items in list to be uppercase}
      if Key in ['a'..'z'] then Dec(Key,32); {Force Uppercase only!}
      with (Sender as TComboBox) do
      begin
        SelSt := SelStart;
        if (Key = Chr(vk_Back)) and (SelLength <> 0) then
         TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelLength+SelStart+1,255)    else if Key = Chr(vk_Back) then {SelLength = 0}
         TmpStr := Copy(Text,1,SelStart-1)+Copy(Text,SelStart+1,255)
        else {Key in ['A'..'Z', etc]}
         TmpStr := Copy(Text,1,SelStart)+Key+Copy(Text,SelLength+SelStart+1,255);
        if TmpStr = '' then Exit;
        { update SelSt to the current insertion point }    if (Key = Chr(vk_Back)) and (SelSt > 0) then Dec(SelSt)    else if Key <> Chr(vk_Back) then Inc(SelSt);
        Key := #0; { indicate that key was handled }
        if SelSt = 0 then 
        begin
          Text:= '';
          Exit;
        end;   {Now that TmpStr is the currently typed string, see if we can locate a match }    Found := False;
        for i := 1 to Items.Count do
          if Copy(Items[i-1],1,Length(TmpStr)) = TmpStr then
          begin
            Text := Items[i-1]; { update to the match that was found }
            ItemIndex := i-1;
            Found := True;
            Break;
          end;
        if Found then { select the untyped end of the string }
        begin
          SelStart := SelSt;
          SelLength := Length(Text)-SelSt;    end
        else Beep;
      end;
    end;
      

  3.   

    s:='aa bb cc dd';
      i:=pos(' ',s);
      while i<>0 do
      begin
        showmessage(copy(s,0,i-1)); //你要的结果
        delete(s,1,i);
        i:=pos(' ',s);
      end;
      

  4.   

    java.util.regex.pattern 类里面的 split 方法!
      

  5.   

    利用函数:(包含在strUtils单元)
    function MidStr(const AText:string;Const AStart,ACount:integer):String;
    功能:在AText中从Astart位置截取Acount长度的字符串,返回此字符串;
      

  6.   

    用pos取空格位置,用copy取空格前的字符