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;
使用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;
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;
然后利用STRINGLIST分割,STRING[I]为空的就DELETE.最终的STRINGLIST就是所要的数字
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;