comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Beginner Question
Date: Thu, 21 Oct 2010 09:28:45 +0200
Date: 2010-10-21T09:28:42+02:00	[thread overview]
Message-ID: <6fnob3l0226$.2j1dfyz9j239.dlg@40tude.net> (raw)
In-Reply-To: 90ceb514-83aa-44c2-b253-218956d8426d@d17g2000yqm.googlegroups.com

On Wed, 20 Oct 2010 14:41:08 -0700 (PDT), SpoonThief wrote:

> So, I have a question that may seem painfully obvious, but how does
> one go about parsing a Float from a string that has other data in it
> too? I'm getting a line from the keyboard that has a float and a
> custom type in it, and I need to separate the two values.

I have a set of libraries for parsing strings. This one is for integer and
floating point numbers:

http://www.dmitry-kazakov.de/ada/strings_edit.htm

> I'm using a
> call to Get_Line to get the entire line the user entered as a string,

You will call Get, which takes a float number at the current string
position and then advances the position pointer behind the number.

[ For dimensioned floating point number parsing see:
http://www.dmitry-kazakov.de/ada/units.htm ]

> and when I try to call Float'Value (In_String (1 .. Last)), I get a
> constraint error. Is there any way to parse a float and a custom
> subtype (Excellent, Good, Fair, Poor) from one string, or am I going
> about this the entirely wrong way?

http://www.dmitry-kazakov.de/ada/tables.htm

It pursues the same principle. You have a table of tokens (mapping of texts
to some type). The table has the operation Get, which matches the string at
the current position, finds the longest match, returns the corresponding
value and advances the position pointer.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



      parent reply	other threads:[~2010-10-21  7:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-20 21:41 Beginner Question SpoonThief
2010-10-20 22:43 ` Jeffrey Carter
2010-10-20 22:45 ` Adam Beneschan
2010-10-21  7:28 ` Dmitry A. Kazakov [this message]
replies disabled

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