有没有判断字符串是否位数字的函数(1分)

  • 主题发起人 yangpeng0622
  • 开始时间
Y

yangpeng0622

Unregistered / Unconfirmed
GUEST, unregistred user!
有没有判断字符串是否位数字的函数
 
只好自己写
 
function m_CkNum(a:char):boolean;
const aa=['1','2','3','4','5','6','7','8','9','0','.',chr(8),chr(161)];
begin
if not (a in aa) then
begin
ShowMessage('您的输入不正确');
result:=false;
exit;
end;
//-----------
if (a=chr(161)) then
a:='.';
result:=true;
end;
 
有判断是否为整数的
StrToIntDef(S: String
DefautValue:Integer);
如果等于DefaultValue则认为不是合法整数
使用try语句也可以完成测试,但是会在开发环境下触发异常
 
function IsNum(const S:String):Boolean;
begin
try
StrToFloat(S);
Result := True;
execpt
Result := False;
end;
 
try
Edit1.text:=floattostr(strtofloat(Edit1.text))
except
showmessage('大哥,不要乱输');
end;
 
VAL可以判断
 
同意以上所有的.
 
我也用HeBaisong的方法
 
接受答案了.
 
顶部