onverts a string that represents an integer (decimal or hex notation) to a number.UnitSysUtilsCategorytype conversion routinesDelphi syntax:function StrToInt(const S: string): Integer; DescriptionStrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.This example uses two edit boxes and a button on a form. When the user clicks the button, the code converts the values in the edit boxes to numbers, adds them, and displays a message indicating the sum:procedure TForm1.Button1Click(Sender: TObject);var I: Integer; J: Integer; begin I := StrToInt(Edit1.Text); J := StrToInt(Edit2.Text); ShowMessage(IntToStr(I + J)); end;
var a:string; b:integer; begin a:='12354'; b:= StrToInt(b);
strtoint(edit1.text) //在括号里是字符类型。 strtofloat(edit1.text) //str 转换成 real 类型;
DescriptionStrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.This example uses two edit boxes and a button on a form. When the user clicks the button, the code converts the values in the edit boxes to numbers, adds them, and displays a message indicating the sum:procedure TForm1.Button1Click(Sender: TObject);var
I: Integer;
J: Integer;
begin
I := StrToInt(Edit1.Text);
J := StrToInt(Edit2.Text);
ShowMessage(IntToStr(I + J));
end;
a:string;
b:integer;
begin
a:='12354';
b:= StrToInt(b);
strtofloat(edit1.text) //str 转换成 real 类型;
strtoint('字符串');
except
showmessage('不是整数');
end;
请关注:
http://expert.csdn.net/Expert/topic/1733/1733460.xml?temp=.5655023
http://expert.csdn.net/Expert/topic/1733/1733461.xml?temp=.5569574
http://expert.csdn.net/Expert/topic/1733/1733463.xml?temp=.2091638
http://expert.csdn.net/Expert/topic/1733/1733464.xml?temp=.5237543
半小时结贴
a:string;
b:integer;
begin
b:= StrToInt(a);
var
E: Integer;
begin
Val(S, Result, E);
if E <> 0 then ConvertErrorFmt(@SInvalidInteger, [S]);
end;