comp.lang.ada
 help / color / mirror / Atom feed
* How to get an ASCII code ?
@ 2001-10-30 12:59 Apokrif
  2001-10-30 14:22 ` Matthew Heaney
  0 siblings, 1 reply; 5+ messages in thread
From: Apokrif @ 2001-10-30 12:59 UTC (permalink / raw)



How can I get the ASCII code for a given character in ADA ? Is there a function 
similar to
Pascal 'ord' ?

-- 
User of http://www.foorum.com/. The best tools for usenet searching.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get an ASCII code ?
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew Heaney @ 2001-10-30 14:22 UTC (permalink / raw)



"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.











^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get an ASCII code ?
  2001-10-30 14:22 ` Matthew Heaney
@ 2001-10-30 15:16   ` Marin David Condic
  2001-10-30 23:19     ` Nick Roberts
  0 siblings, 1 reply; 5+ messages in thread
From: Marin David Condic @ 2001-10-30 15:16 UTC (permalink / raw)


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.
>
>
>
>
>
>
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get an ASCII code ?
  2001-10-30 15:16   ` Marin David Condic
@ 2001-10-30 23:19     ` Nick Roberts
  2001-10-31 14:48       ` Marin David Condic
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Roberts @ 2001-10-30 23:19 UTC (permalink / raw)


Yes, I think you should add that the standard package Ada.Characters.Latin_1
(and maybe other non-standard packages like it) can be used to get control
characters (and esoteric characters that might not be available on one's
keyboard).

--
Nick Roberts


"Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org> wrote in
message news:9rmg8e$ni8$1@nh.pace.co.uk...
> This one comes up a lot. I wrote this for the FAQ & sent it to David.
> Anybody see anything that should be added/changed?






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get an ASCII code ?
  2001-10-30 23:19     ` Nick Roberts
@ 2001-10-31 14:48       ` Marin David Condic
  0 siblings, 0 replies; 5+ messages in thread
From: Marin David Condic @ 2001-10-31 14:48 UTC (permalink / raw)


That might be answering another FAQ - possibly a separate writeup? However,
your point is taken. I'll a) add a reference to Ada.Characters.Latin_1 at
the end and b) make a mention of it in the text.

If you can phrase a FAQ on that, perhaps you could submit a bit more
detailed explanation to David Boton & contribute to the FAQ?

MDC
--
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/


"Nick Roberts" <nickroberts@adaos.worldonline.co.uk> wrote in message
news:9rnclj$uqhpr$1@ID-25716.news.dfncis.de...
> Yes, I think you should add that the standard package
Ada.Characters.Latin_1
> (and maybe other non-standard packages like it) can be used to get control
> characters (and esoteric characters that might not be available on one's
> keyboard).
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-10-31 14:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2001-10-30 23:19     ` Nick Roberts
2001-10-31 14:48       ` Marin David Condic

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