DelphiFAQ Home Search:

Does a string looks like an integer?

 

comments1 comments. Current rating: 3 stars (1 votes). Leave comments and/ or rate it.

Use this function to determine, whether a given string represents an integer.

function IsInteger(TestThis: String): Boolean;
begin
  try
    StrToInt(TestThis);
  except
    on EConvertError do
      result := False;
  else
    result := True;
  end;
end;
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html

Comments:

2006-08-21, 10:06:46
anonymous from Belgium  
rating
even better use function TryStrToInt (new in Delphi 6 or before),
so that no exception event is triggered in the debugger:

function IsInteger(TestThis: String): Boolean;
var V : integer;
begin
Result := TryStrToInt(TestThis, V);
// if Result = true, V holds the value
end;

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: