comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Mize <smize@link.com>
Subject: Re: String to Integer
Date: 1997/07/16
Date: 1997-07-16T00:00:00+00:00	[thread overview]
Message-ID: <33CD07B9.3DFA@link.com> (raw)
In-Reply-To: 5qglt7$cba$1@news.fsu.edu


Charles Hill wrote:
> 
> I have a string in which an integer is stored.  I'd like to hear
> from someone who might know a convenient way to convert this to
> an actual integer.  I'm wondering if there is a function built
> into one of the Ada packages to do this, but I haven't found one
> yet.
> 
> I would appreciate any advice anyone has.

Do you mean that the string contains the characters that
represent the number, or that the string storage is also
used as binary storage for an integer?

In the first case (e.g. "301") you can use integer'image and
integer'value to translate between the string and the integer
value.  If your string is a buffer that may have garbage after
the end of the number (e.g., a null-terminated varying-length
string in a fixed-length buffer), it may be simpler to use
Ada.Text_Io.Integer_Io.Get from string, since it stops at the
first non-numeric character (while Integer'Value would try to
translate the entire string, and fail if there is anything in
it but the integer and blanks).

If you have a binary representation of an integer in your
string, you should use unchecked_conversion.

Samuel Mize




  parent reply	other threads:[~1997-07-16  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-15  0:00 String to Integer Charles Hill
1997-07-15  0:00 ` John Herro
1997-07-16  0:00 ` Martin C. Carlisle
1997-07-16  0:00 ` Samuel Mize [this message]
1997-07-16  0:00 ` Robert Dewar
1997-07-17  0:00   ` Embedding Text Data in Source (Was Re: String to Integer) John M. Mills
1997-07-17  0:00     ` Samuel T. Harris
1997-07-19  0:00     ` Matthew Heaney
1997-07-17  0:00 ` String to Integer Michael F Brenner
     [not found]   ` <5qlrue$3ft@top.mitre.org>
1997-07-18  0:00     ` Samuel Mize
replies disabled

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