可以用以下这个函数(刚刚给你写的 :) function GetNumFromStr(AStr: String): String; var I, J: Integer; RStr: String; begin for I := 0 to Length(AStr) - 1 do begin for J := 48 to 57 do begin if Copy(AStr, I + 1, 1) = Chr(J) then RStr := RStr + Chr(J); end; end; Result := RStr; end; //调用方式 GetNumFromStr('abc0001') 可以返回 '0001'三少 :o) [别人笑我太轻狂,我笑他人看不穿]
More Easy: for i := 0 to Length(s) do //s是你的初始字符串 begin if (s[i] in ['0'..'9']) then st := st + s[i]; //st是初始字符串中的数字 end;
function GetNumFromStr(const str: String;const hex:boolean=false): String; var i:integer; charset:Set of char; begin if hex then charset:=['0'..'9','a'..'f','A'..'F','.'] else charset:=['0'..'9','.']; for i := 1 to Length(str) do begin if (str[i] in charset) then result:= result + uppercase(str[i]); end; end;可以取得十六进制的数字!可以包含小数点,但你必须保证只有一个小数点!
function GetNumFromStr(AStr: String): String;
var
I, J: Integer;
RStr: String;
begin
for I := 0 to Length(AStr) - 1 do
begin
for J := 48 to 57 do
begin
if Copy(AStr, I + 1, 1) = Chr(J) then
RStr := RStr + Chr(J);
end;
end;
Result := RStr;
end;
//调用方式 GetNumFromStr('abc0001') 可以返回 '0001'三少 :o)
[别人笑我太轻狂,我笑他人看不穿]
for i := 0 to Length(s) do //s是你的初始字符串
begin
if (s[i] in ['0'..'9']) then
st := st + s[i]; //st是初始字符串中的数字
end;
var
i:integer;
charset:Set of char;
begin
if hex then
charset:=['0'..'9','a'..'f','A'..'F','.']
else
charset:=['0'..'9','.'];
for i := 1 to Length(str) do
begin
if (str[i] in charset) then
result:= result + uppercase(str[i]);
end;
end;可以取得十六进制的数字!可以包含小数点,但你必须保证只有一个小数点!