function GetNum(const AStr: String): Double;
var
iLPos, iRPos: Integer;//取出数字的左边第一次位置和右边第一次位置
sTarget: string;//数字字符串
function GetLRPos(IsLPos: Boolean): Integer;//获得左右起始位置
var
i: Integer;
begin
Result := -1;
if IsLPos then
begin
for i := 1 to Length(AStr) do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
if not IsLPos then
begin
for i := Length(AStr) downto 1 do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
end;
begin
Result := -1;
iLPos := GetLRPos(True);
iRPos := GetLRPos(False);
sTarget := copy(AStr, iLPos, iRPos - iLPos + 1);//取出目标字符串
Result := StrToFloat(sTarget);//转化成数字字符串
end;//简单的测试程序
procedure TForm1.btn1Click(Sender: TObject);
var
ret: Double;
begin
ret := GetNum(edt1.Text);
ShowMessage(FloatToStr(ret));
end;function GetNum(const AStr: String): Double;
var
iLPos, iRPos: Integer;//取出数字的左边第一次位置和右边第一次位置
sTarget: string;//数字字符串
function GetLRPos(IsLPos: Boolean): Integer;//获得左右起始位置
var
i: Integer;
begin
Result := -1;
if IsLPos then
begin
for i := 1 to Length(AStr) do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
if not IsLPos then
begin
for i := Length(AStr) downto 1 do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
end;
begin
Result := -1;
iLPos := GetLRPos(True);
iRPos := GetLRPos(False);
sTarget := copy(AStr, iLPos, iRPos - iLPos + 1);//取出目标字符串
Result := StrToFloat(sTarget);//转化成数字字符串
end;//简单的测试程序
procedure TForm1.btn1Click(Sender: TObject);
var
ret: Double;
begin
ret := GetNum(edt1.Text);
ShowMessage(FloatToStr(ret));
end;
var
iLPos, iRPos: Integer;//取出数字的左边第一次位置和右边第一次位置
sTarget: string;//数字字符串
function GetLRPos(IsLPos: Boolean): Integer;//获得左右起始位置
var
i: Integer;
begin
Result := -1;
if IsLPos then
begin
for i := 1 to Length(AStr) do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
if not IsLPos then
begin
for i := Length(AStr) downto 1 do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
end;
begin
Result := -1;
iLPos := GetLRPos(True);
iRPos := GetLRPos(False);
sTarget := copy(AStr, iLPos, iRPos - iLPos + 1);//取出目标字符串
Result := StrToFloat(sTarget);//转化成数字字符串
end;//简单的测试程序
procedure TForm1.btn1Click(Sender: TObject);
var
ret: Double;
begin
ret := GetNum(edt1.Text);
ShowMessage(FloatToStr(ret));
end;function GetNum(const AStr: String): Double;
var
iLPos, iRPos: Integer;//取出数字的左边第一次位置和右边第一次位置
sTarget: string;//数字字符串
function GetLRPos(IsLPos: Boolean): Integer;//获得左右起始位置
var
i: Integer;
begin
Result := -1;
if IsLPos then
begin
for i := 1 to Length(AStr) do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
if not IsLPos then
begin
for i := Length(AStr) downto 1 do
if AStr[i] in ['0'..'9'] then
begin
Result := i;
Exit;
end;
end;
end;
begin
Result := -1;
iLPos := GetLRPos(True);
iRPos := GetLRPos(False);
sTarget := copy(AStr, iLPos, iRPos - iLPos + 1);//取出目标字符串
Result := StrToFloat(sTarget);//转化成数字字符串
end;//简单的测试程序
procedure TForm1.btn1Click(Sender: TObject);
var
ret: Double;
begin
ret := GetNum(edt1.Text);
ShowMessage(FloatToStr(ret));
end;
123456789,通过
123456abc,通过
abc123456,通过
a123456bc,通过
123abc456,不通过