From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bac902cf9fd6564b X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: Case Sensitivity Date: 2000/05/11 Message-ID: <8fekov$7pk$1@nnrp1.deja.com>#1/1 X-Deja-AN: 622144875 References: <958056490.47876@hearts.q-net.net.au> X-Http-Proxy: 1.0 x43.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Thu May 11 15:48:55 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-05-11T00:00:00+00:00 List-Id: In article <958056490.47876@hearts.q-net.net.au>, "Cameron McShane" wrote: > Hey > > I am doing a project for Uni, and am a bit stuck. > > We need a menu that needs to be case-'in'sensitive. I am using an enumerated > data type for the 3 menu options ie: > > type Menu_Options is (buy, read, done) > > If the user is to be allowed to enter Buy or BUY or bUy - etc, do I need to > make the data type > > type Menu_Options is (buy, Buy, bUY, etc > > or is there a way of converting user input to all lower case? Yes. In the Latin_1 character collating sequence, it just so happens that the characters 'a' through 'z' all have the same relative position to each other as the characters 'A' through 'Z'. The lower-case letters have a larger value than the upper case letters. (See Ada.Characters.Latin_1) So the traditional manual way to do this would be to find the difference in the integer position of an upper case character from that of its lower-case counterpart (eg: 'A' and 'a'). Then you can add that difference to the integer position of every upper-case letter you encounter. Then you just need to find the character value for that resulting integer position. There are predefined attributes that you can apply to characters to convert between their character value and their integer position. (This reads pretty complicated, but the code's really very simple). But you don't have to do this manually (unless your teacher wants you to). Take out your handy-dandy Ada LRM (if you don't have one, there's one online at http://www.adapower.com ) and look through the routines in the standard Ada library in Appendix A. There are a couple of sets of packages in there that provide useful routines for doing this kind of thing. There are packages for doing lots of other neat stuff too, so be sure to look through them all. While you're at it, do yourself a favor and read through appendix K (Language Defined Attributes). There's lots of vital stuff in there to make your life easier. -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/ Before you buy.