comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: How to get an ASCII code ?
Date: Tue, 30 Oct 2001 10:16:27 -0500
Date: 2001-10-30T15:16:30+00:00	[thread overview]
Message-ID: <9rmg8e$ni8$1@nh.pace.co.uk> (raw)
In-Reply-To: tttdmp64dqv206@corp.supernews.com

This one comes up a lot. I wrote this for the FAQ & sent it to David.
Anybody see anything that should be added/changed?

Q: How can I get the ASCII code for a given character in Ada?

A: Learn about attributes in Ada - there are a lot of them that are *very*
helpful in working with the characteristics of data types and other things.
In this case, you are interested in the 'Pos and 'Val attributes for
discrete types. One returns the numeric position of an object of a discrete
type. The other returns the discrete type value of a numeric position. As an
example:

X   : Character := 'A' ;
Y   : Integer   := 0 ;
....
Y   := Character'Pos (X) ;   -- Y now contains the ASCII value of 'A'
....
X   := Character'Val (35) ;  -- X now contains the character '#'

References:

ARM 3.5 (11), ARM K (175-178), ARM K (258-261)

Submitted by: Marin David Condic

--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/

"Matthew Heaney" <mheaney@on2.com> wrote in message
news:tttdmp64dqv206@corp.supernews.com...
>
> "Apokrif" <apokrif1@yahoo.com> wrote in message
> news:20011030-135944-285742@foorum.com...
> >
> > How can I get the ASCII code for a given character in Ada? Is there a
> function
> > similar to Pascal 'ord' ?
>
> declare
>    C : constant Character := 'a';
>    I : constant Natural := Character'Pos (C);
> begin
>
> To back the other way, use Character'Val.
>
>
>
>
>
>
>
>





  reply	other threads:[~2001-10-30 15:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-30 12:59 How to get an ASCII code ? Apokrif
2001-10-30 14:22 ` Matthew Heaney
2001-10-30 15:16   ` Marin David Condic [this message]
2001-10-30 23:19     ` Nick Roberts
2001-10-31 14:48       ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox