在Delphi中检查值是否为日期/数字的正确方法是什么
发布时间:2020-12-15 04:21:48 所属栏目:大数据 来源:网络整理
导读:在Delphi中检查值是否为日期/数字的正确方法是什么? 我知道其他语言有像isDate和isNaN这样的函数,但Delphi的等价物是什么?在我有这个的那一刻 function isNumeric(s1:string):boolean;begin // will throw exception if its not a number // there must be
在Delphi中检查值是否为日期/数字的正确方法是什么?
我知道其他语言有像isDate和isNaN这样的函数,但Delphi的等价物是什么?在我有这个的那一刻 function isNumeric(s1:string):boolean; begin // will throw exception if its not a number // there must be a better way to do this!! try StrTofloat(s1); result := TRUE ; except result := FALSE; end; end; 但抛出异常不能很好,而且每次调用代码时我都会看到异常对话,这会使调试变得困难. 解决方法
对于整数,您可以使用TryStrToInt检查和转换而不抛出异常:
function TryStrToInt(const s: string; out i : integer): boolean; 我不完全确定浮点数有完整的等价物,所以你可能需要使用StrToFloat()并接受TFormatException的可能性. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |