Delphi 从字符串中提取数字
function GetNumberFromStr(strIn: string; sFlag: string): string;
var
i: Integer;
tempStr: string;
begin
tempStr := '';
if Length(strIn) = 0 then
begin
Result := '';
exit;
end;
for i := 1 to Length(strIn) do
begin
if strIn[i] = sFlag then //截取到sFlag位置结束
Break;
if IsNumber(strIn[i]) then //isNumber--System.Character
begin
tempStr := tempStr + strIn[i];
end;
end;
Result := tempStr;
end;
如果是高版本Delphi 需引用System.Character
如果是在Delphi7,还需要一个判断是否是数子的函数
function IsNumber(N: string): Boolean;
var
I: Integer;
begin
Result := True;
if Trim(N) = '' then
Exit;
if (Length(Trim(N)) > 1) and (Trim(N)[1] = '0') then
Exit;
for I := 1 to Length(N) do
begin
if not (N[I] in ['0'..'9']) then
begin
Result := False;
Break;
end;
end;
end;
如果觉得文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
作者:YXGust
出处:https://www.cnblogs.com/YXGust/p/16736795.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
本博文版权归本博主所有,转载请注明原文链接