有这么一串数字:10-20-8-9-6.怎么一个一个提取里面的数字?
数字个数没有限制。
或者是20*5*6*9.
这种。

解决方案 »

  1.   

    function GetDigi(InStr: string): string;
    var
      Count0 : integer;
      OutStr : string;
    begin
      OutStr := '';
      for Count0 := 1 to length(InStr) do 
        if ord(InStr[Count0]) in [ord('0')..ord('9')] then
          OutStr := OutStr + InStr[Count0];
      Result := OutStr; 
    end;
      

  2.   

    遍历每一个CHAR,只要不是'0'~'9'就统一replace成特定字符.
    然后利用STRINGLIST分割,STRING[I]为空的就DELETE.最终的STRINGLIST就是所要的数字
      

  3.   

    分隔符是否固定,如果固定可直接导入到TStringList中,指定分隔符
      

  4.   

    使用TStringList和replace都可以實現的...(這裡寫一個TStringList的,你自己變通一下...)function TRES_CQ_JB_F.Returndata(bm:string):string;
    var
      Temp:TStrings;  
      i:Integer;
    begin
      Temp:=TStringList.Create;
      Result:='';
      try
        Temp.DelimitedText:=bm;
        Temp.Delimiter:=',';
        for i:=0 to Temp.Count -1 do
          Result:=Result+QuotedStr(Temp[i])+',';
        Result:=Copy(Result,1,Length(Result)-1);
      finally
        Temp.Free;
      end;
    end;