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;
标签:begin,end,string,strIn,Delphi,Length,tempStr,字符串,提取
From: https://www.cnblogs.com/YXGust/p/16736795.html