Converts a string that represents an integer (decimal or hex notation) to a number.
function StrToInt(const S: string): Integer; overload;
int StrToInt(const AnsiString S);
StrToInt 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.
C++ Examples:
/* 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: */ void __fastcall TForm1::Button1Click(TObject *Sender) { int i1, i2; i1 = StrToInt(Edit1->Text); i2 = StrToInt(Edit2->Text); ShowMessage(IntToStr(i1 + i2)); }
Delphi Examples:
{ 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;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|