Question: How to Check if a String is numeric?

Answer:
If you mean string is 1,2,3,4 ....0 in string mode.
Here the code:

function IsStrANumber(const S: string): Boolean;
var
P: PChar;
begin
P := PChar(S);
Result := False;
while P^ <> #0 do
begin
if not (P^ in ['0'..'9']) then Exit;
Inc(P);
end;
Result := True;
end;

3 Responses so far.

  1. daspeac says:

    I have heard about another way of cheap sql database repair. Besides, you can visit my blogs at: http://daspeac.livejournal.com/ or http://daspeac.blogspot.com/ where I’m trying to share my experience with regard to data corruption issues.

  2. Anonymous says:

    or this one

    function IsStrANumber(const S: string): Boolean;
    begin
    Result := True;
    try
    StrToInt(S);
    except
    Result := False;
    end;
    end;

  3. Nelson says:

    Nice one ..thanks for sharing trick questions about Delphi development.

Post a Comment

Thank you for your comment.

Any request and idea are welcome.

CLICK TO REGISTER