comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon.j.wright@mac.com>
Subject: Re: Converting Type Characters to type string
Date: Tue, 01 Apr 2008 22:11:26 +0100
Date: 2008-04-01T22:11:26+01:00	[thread overview]
Message-ID: <m28wzx9t6p.fsf@mac.com> (raw)
In-Reply-To: fe50b4d0-8942-4f14-8837-e3cc59c24809@f63g2000hsf.googlegroups.com

jedivaughn <jedivaughn14@gmail.com> writes:

> On Apr 1, 1:34 am, Simon Wright <simon.j.wri...@mac.com> wrote:
>> jedivaughn <jedivaugh...@gmail.com> writes:
>> > Ok So I've almost solved my problem. my only question now is I need
>> > to convert one character to an integer. I know the input is a
>> > integer so it's not going to give me a constraint error but how will
>> > I convert one character to an integer?
>>
>> Make a one-character String holding your Character & convert that?
>>
>> with ada.text_io;
>> procedure blah is
>>   i : integer := integer'value (string'(1 .. 1 => '7'));
>> begin
>>   ada.text_io.put_line ("i => " & integer'image (i));
>> end blah;
>
>
> not exactly what I was looking for. I have a number stored in a
> character. and I want to turn that into a integer. so I can add it to
> another integer. So say I have the number '5' stored in a character
> and I want that in an integer not a character or string. how would I
> do that?

It may not be what you are looking for but it is **exactly** what you
asked for!

If I'd said

  function to_integer (c : character) return integer is
  begin
    return integer'value (string'(1 .. 1 => c));
  end to_integer;

would it be clearer?

You could try compiling and running my example, I assure you it works.



  parent reply	other threads:[~2008-04-01 21:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-30 20:04 Converting Type Characters to type string jedivaughn
2008-03-30 20:19 ` Pascal Obry
2008-03-30 21:08   ` jedivaughn
2008-03-30 21:28     ` jimmaureenrogers
2008-03-30 21:38     ` Ludovic Brenta
2008-03-30 21:48   ` Georg Bauhaus
2008-03-30 23:52     ` jedivaughn
2008-03-31  3:04       ` george.priv
2008-03-31  4:00         ` tmoran
2008-03-31  8:54           ` Ludovic Brenta
2008-03-31  9:59             ` Dmitry A. Kazakov
2008-03-31 10:59               ` Jean-Pierre Rosen
2008-03-31 13:50                 ` jedivaughn
2008-03-31 14:11                   ` Ludovic Brenta
2008-03-31 14:21                   ` Dmitry A. Kazakov
2008-03-31 14:44                     ` jedivaughn
2008-03-31 15:41                       ` Adam Beneschan
2008-03-31 20:26                         ` Maciej Sobczak
2008-03-31 22:06                           ` Georg Bauhaus
2008-03-31 22:33                           ` Adam Beneschan
2008-04-01  1:00                             ` jedivaughn
2008-04-01  5:34                               ` Simon Wright
2008-04-01 11:22                                 ` jedivaughn
2008-04-01 12:00                                   ` jimmaureenrogers
2008-04-01 13:22                                     ` jedivaughn
2008-04-01 17:03                                       ` Adam Beneschan
2008-04-01 21:11                                   ` Simon Wright [this message]
2008-04-01 22:22                                     ` jedivaughn
2008-04-03  5:54                                   ` tmoran
2008-04-03 14:38                                     ` Adam Beneschan
2008-04-01 16:58                               ` Adam Beneschan
2008-03-31 15:45                       ` Dmitry A. Kazakov
replies disabled

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