comp.lang.ada
 help / color / mirror / Atom feed
* Re: String handling???
  2001-06-24 17:24 String handling??? Michael Andersson
@ 2001-06-24 12:30 ` Dale Stanbrough
  2001-06-24 12:30 ` David C. Hoos, Sr.
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dale Stanbrough @ 2001-06-24 12:30 UTC (permalink / raw)


Michael Andersson wrote:

> Hi!
> I'm currently trying to write a text file parser from my collage project
> and I'm looking for some functions i Ada that works like the sprint
> function in C. Is there such a function?
> The thing is that I want to extract numbers from a string and I don't
> know how.


You can achieve some of this by using the put routines, with
a string as the first parameter, rather than a file.

All the usual caveats for dealing with Ada strings remain, such
as constantly remebering where you are up to when appending
new values.

Dale



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

* Re: String handling???
  2001-06-24 17:24 String handling??? Michael Andersson
  2001-06-24 12:30 ` Dale Stanbrough
@ 2001-06-24 12:30 ` David C. Hoos, Sr.
  2001-06-24 12:49 ` Larry Kilgallen
  2001-06-24 23:56 ` Jeffrey Carter
  3 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 2001-06-24 12:30 UTC (permalink / raw)
  To: comp.lang.ada; +Cc: a98mican

There is no sprint function in any C library of which I am aware.  You are
probably thinking of sprintf, but even that function is of no help in
extracting
numbers from a string.  To do that, in C, one would use scanf, or one of its
companion xscanf functions.

That said, to do the same thing in Ada, one would make use of the 'Value
attribute of the corresponding numeric type to obtain the numeric
value from its string representation.

For example, to obtain the numeric value from a string of digits, one
would use the Integer'Value function, passing the string as the argument.

To tokenize a string (say, from a file), one would use the Find_Token
procedure of the Ada.Strings.Fixed package.

----- Original Message -----
From: "Michael Andersson" <a98mican@ida.his.se>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: June 24, 2001 12:24 PM
Subject: String handling???


> Hi!
> I'm currently trying to write a text file parser from my collage project
> and I'm looking for some functions i Ada that works like the sprint
> function in C. Is there such a function?
> The thing is that I want to extract numbers from a string and I don't
> know how.
>
> Need your help, please!
> /Michael Andersson
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




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

* Re: String handling???
  2001-06-24 17:24 String handling??? Michael Andersson
  2001-06-24 12:30 ` Dale Stanbrough
  2001-06-24 12:30 ` David C. Hoos, Sr.
@ 2001-06-24 12:49 ` Larry Kilgallen
  2001-06-24 23:56 ` Jeffrey Carter
  3 siblings, 0 replies; 5+ messages in thread
From: Larry Kilgallen @ 2001-06-24 12:49 UTC (permalink / raw)


In article <3B362243.EA4AA94E@ida.his.se>, Michael Andersson <a98mican@ida.his.se> writes:
> Hi!
> I'm currently trying to write a text file parser from my collage project
> and I'm looking for some functions i Ada that works like the sprint
> function in C. Is there such a function?

In general, looking for a function to "do it like language X" is a bad idea.
Please consult your Ada textbook.  Every one I have bought gives examples of
string handling.



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

* String handling???
@ 2001-06-24 17:24 Michael Andersson
  2001-06-24 12:30 ` Dale Stanbrough
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michael Andersson @ 2001-06-24 17:24 UTC (permalink / raw)


Hi!
I'm currently trying to write a text file parser from my collage project
and I'm looking for some functions i Ada that works like the sprint
function in C. Is there such a function?
The thing is that I want to extract numbers from a string and I don't
know how.

Need your help, please!
/Michael Andersson



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

* Re: String handling???
  2001-06-24 17:24 String handling??? Michael Andersson
                   ` (2 preceding siblings ...)
  2001-06-24 12:49 ` Larry Kilgallen
@ 2001-06-24 23:56 ` Jeffrey Carter
  3 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Carter @ 2001-06-24 23:56 UTC (permalink / raw)


Michael Andersson wrote:
> 
> I'm currently trying to write a text file parser from my collage project
> and I'm looking for some functions i Ada that works like the sprint
> function in C. Is there such a function?
> The thing is that I want to extract numbers from a string and I don't
> know how.

Assuming that "extract numbers" means convert from a text representation
in a String into the internal representation for a numeric type, you
have a number of options.

If your String contains a single value, possibly with leading or
trailing blanks, you can use the 'Value attribute. See your text or ARM
Annex K.

For more complex situations, there are procedures in Ada.Text_IO that
"read" from a string. See your text or ARM Annex A.10.

For parsing Strings, you might find the subprograms in Ada.Strings.Fixed
useful. See your text or ARM Annex A.4.3. The other child packages of
Ada.Strings might also be of interest.

However, none of these work exactly like sprint (if that really is a C
function for extracting numbers from a string). In general, Ada Strings
do not work like C strings. If that really is a requirement, you'll have
to write your own or import the C functions.

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail



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

end of thread, other threads:[~2001-06-24 23:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-24 17:24 String handling??? Michael Andersson
2001-06-24 12:30 ` Dale Stanbrough
2001-06-24 12:30 ` David C. Hoos, Sr.
2001-06-24 12:49 ` Larry Kilgallen
2001-06-24 23:56 ` Jeffrey Carter

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