如何判断一字符串是否为数字串?
如: '123.456000' 为数字,但'+123Edfd我12'为非字符串.
而'+123E-7',为数字串.
Delphi7帮助中:
对function StrToFloat(const S: string): Extended; overload;
中S的定义
S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored.若S为'+123Edfd我12',通过StrToFloat转换不成功,会引发EConvertError
异常.
能否通过这一点来判断S是否为数字串?(最好能简化为用if 判断)
本人一直以来对异常(C++,Delphi)都不明白,Delphi也刚学不久,望哪位大侠赐教!
如: '123.456000' 为数字,但'+123Edfd我12'为非字符串.
而'+123E-7',为数字串.
Delphi7帮助中:
对function StrToFloat(const S: string): Extended; overload;
中S的定义
S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored.若S为'+123Edfd我12',通过StrToFloat转换不成功,会引发EConvertError
异常.
能否通过这一点来判断S是否为数字串?(最好能简化为用if 判断)
本人一直以来对异常(C++,Delphi)都不明白,Delphi也刚学不久,望哪位大侠赐教!
解决方案 »
- Delphi中流的ReadBuffer和Read什么区别?
- 100分,求这样的SQL如何写?或实现方法。
- MSComm控件安装后,在ActiveX面板中找不到相应的组件
- 晕了,折腾很久没有搞定,treeView节点图标如何实现想资源管理器那样的效果?
- 如何对一张表插入多条记录?
- 请问listview的排序问题!!!!!!!!!!????????????????????????????
- 没有办法不给你mrfanghansheng(☆☆☆木鱼☆☆☆) 100不行
- 高分求dbgrid中每行显示的checkBox的控件
- 没有Canvas就不能画了么?苦恼中…………
- 数据表中性别是'1'或'2',能否从DBGrid中显示成'男'或'女'?
- 关于大富翁网站这两天打不开的原因
- 怎样使用打印机的控制码??
NumReal: Real;Try
NumReal := StrToFloat(Str);
Except
ShowMessage(Str+' 不是一個有效的數值 ');
//Abort;
.....
End;
begin
Result := True;
try
n := StrToInt('你的字符串');
//类似的,其他类型数字用相应的函数
except
//如果不是数字字符串会出错,执行这里的代码
Result := False;
end;
end;