strtoint() 你这是检验一个串是否为数字串? 错了吧 这是将一字符转换成整型! function StrToInt(const S: string): Integer;
function IsInt(AStr: string): Boolean; var Value, Code: Integer; begin Val(AStr, Value, Code); Result := Code = 0; end;function IsFloat(AStr: string): Boolean; var Value: Real; Code: Integer; begin Val(AStr, Value, Code); Result := Code = 0; end;
还有StrToCurr() function StrToCurr(const S: string): Currency; 把字符串转换成货币型!StrToFloat() function StrToFloat(const S: string): Extended; 把字符串转换成浮点型!
Delphi's help: ///////////////////////// Val exampleuses Dialogs; var I, Code: Integer; begin { Get text from TEdit control } Val(Edit1.Text, I, Code); { Error during conversion to integer? } if Code <> 0 then MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk); else Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));end;
你这是检验一个串是否为数字串?
错了吧
这是将一字符转换成整型!
function StrToInt(const S: string): Integer;
var
Value, Code: Integer;
begin
Val(AStr, Value, Code);
Result := Code = 0;
end;function IsFloat(AStr: string): Boolean;
var
Value: Real;
Code: Integer;
begin
Val(AStr, Value, Code);
Result := Code = 0;
end;
function StrToCurr(const S: string): Currency;
把字符串转换成货币型!StrToFloat()
function StrToFloat(const S: string): Extended;
把字符串转换成浮点型!
/////////////////////////
Val exampleuses Dialogs;
var I, Code: Integer;
begin
{ Get text from TEdit control }
Val(Edit1.Text, I, Code);
{ Error during conversion to integer? }
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk);
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));end;
StrToInt(S);
ShowMessage('是');
Except
ShowMessage('不是');
end;
这不就是现成的函数吗?一个是判断是否整形的,一个是判断是否浮点型。function IsInt(AStr: string): Boolean;
var
Value, Code: Integer;
begin
Val(AStr, Value, Code);
Result := Code = 0;
end;function IsFloat(AStr: string): Boolean;
var
Value: Real;
Code: Integer;
begin
Val(AStr, Value, Code);
Result := Code = 0;
end;
TryStrToInt(S)
TryStrToTime(S)
TryStrToFloat(S)
Try...To...(S)