From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: character matching
Date: Sun, 15 Aug 2004 16:52:49 +0200
Date: 2004-08-15T16:53:16+02:00 [thread overview]
Message-ID: <87zn4wtpvi.fsf@insalien.org> (raw)
In-Reply-To: uNITc.3402$BA5.883@hydra.nntpserver.com
"John J" writes:
> Thanks for the suggestions; however, I'm trying to learn a bit about
> the syntax and capabilities of ADA. Would someone be kind enough to
> give me some examples of how I can use ADA to character match. ie,
> different ways I can use '*', '&' to successfully recognise words
> and sentences.
>
> Thanks
type Category is (Whitespace, Punctuation, Letter, Digit, Other);
function Category_Of (C : in Character) return Category is
begin
case C is
when ' ' | ASCII.TAB => return Whitespace;
when ',' | '.' | '!' | ';' | ':' | '?' => return Punctuation;
when 'a' .. 'z' | 'A' .. 'Z' => return Letter;
when '0' .. '9' => return Digit;
when others => return Other;
end case;
end Category_Of;
I hope this helps you move forward. Is this a homework assignment?
(note that in Ada, a "case" statement is required to process all
possible values of the case_expression (here, C); the compiler will
tell you if you forgot some values, unless as above you use "when
others").
--
Ludovic Brenta.
next prev parent reply other threads:[~2004-08-15 14:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-13 5:23 character matching John J
2004-08-13 10:33 ` David C. Hoos
2004-08-13 11:12 ` Nick Roberts
2004-08-13 18:41 ` Jeffrey Carter
2004-08-15 12:36 ` John J
2004-08-15 14:52 ` Ludovic Brenta [this message]
2004-08-15 21:02 ` Adrian Knoth
2004-08-16 22:26 ` Ludovic Brenta
2004-08-15 17:21 ` Steve
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox