Mirror

Does a string looks like an integer? (Views: 101)


Problem/Question/Abstract:

Does a string looks like an integer?

Answer:

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;


Note: Due to the exception, the program is slow for non-numerical strings. If you expect non-numerical strings very often, you may use a construct basing on the Val() function and evaluate the error code.

<< Back to main page