gpt4 book ai didi

Delphi是数字

转载 作者:行者123 更新时间:2023-12-03 14:34:14 34 4
gpt4 key购买 nike

Delphi中有没有一种方法可以检查字符串是否为数字而不引发异常?

用于 int 解析。

如果使用

则会引发异常
try
StrToInt(s);
except
//exception handling
end;

最佳答案

功能TryStrToInt (const S:字符串;输出值:整数): bool 值;

TryStrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number, which is assigned to Value. If S does not represent a valid number, TryStrToInt returns false; otherwise TryStrToInt returns true.

To accept decimal but not hexadecimal values in the input string, you may use code like this:

function TryDecimalStrToInt( const S: string; out Value: Integer): Boolean;
begin
result := ( pos( '$', S ) = 0 ) and TryStrToInt( S, Value );
end;

关于Delphi是数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4884263/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com