Re: String checking in Delphi 4.

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 06/28/04


Date: Mon, 28 Jun 2004 10:17:51 -0400


"Paul" <p@hotmail.com> wrote in message
news:cbkub5$ij5$1@sparta.btinternet.com...
> I have a string that I need to test for its contents.
> Is there any easy way to check if a string contains all numeric characters
> (0-9)?

IIRC D6 or D7 introduced a routine for this, but I only have D5 and I can't
remember the name. Earlier versions can use something like

function isNumericDigitsOnly (const s : string) : boolean;

begin
result := (Length (s) > 0) and
             (IntToStrDef (s, -1) = IntToStrDef (s, 0)) and
             (not (s [1] in ['$', '+', '-']));
end;

> Also, if the string is 7 characters long and I want to test if the 7th
> character is a letter and all the characters in position 1-6 are numeric,
> can this be easily tested for?

function isGoodForm (const s : string) : boolean;

begin
if (Length (s) > 6)
then result := isNumericDigitsOnly (Copy (s, 1, 6)) and (upCase (Copy (s, 7,
1) [1]) in ['A' .. 'Z'])
else result := false;
end;


Quantcast