Re: character matching
From: Ludovic Brenta (ludovic.brenta_at_insalien.org)
Date: 08/15/04
- Previous message: John J: "Re: character matching"
- In reply to: John J: "Re: character matching"
- Next in thread: Adrian Knoth: "Re: character matching"
- Reply: Adrian Knoth: "Re: character matching"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 15 Aug 2004 16:52:49 +0200
"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.
- Previous message: John J: "Re: character matching"
- In reply to: John J: "Re: character matching"
- Next in thread: Adrian Knoth: "Re: character matching"
- Reply: Adrian Knoth: "Re: character matching"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|