«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

How to check if a string is a number


Checking if a string is a number is quite simple, all we have to do is check if all it's characters are numbers. The situation becomes more complicated when you wish to recognize symbols ('+', '-', '$' etc.), but I'll leave that out for now. This code uses PChar as the parameter for speed reasons. If you want to send a string value to the function just typecast it.

function IsNumber(pcString: PChar): Boolean;
  Result := False;
  while pcString^ <> #0 do // 0 indicates the end of a PChar string
    if not (pcString^ in ['0'..'9']) then
  Result := True;
See an extended version of this routine – IsNumeric – in the Code Snippets Database. This routine can optionally check for floating point numbers.
Author: Unknown
Added: 2007-06-02
Last updated: 2013-10-12

« Return to contents »