* Types Converting
@ 1996-04-27 0:00 HSR Al-Dhaheri
1996-04-27 0:00 ` Joerg Rodemann
0 siblings, 1 reply; 3+ messages in thread
From: HSR Al-Dhaheri @ 1996-04-27 0:00 UTC (permalink / raw)
Hi,
I would like to know how can you convert an integer to a string in Ada.
For example, if you've declared a variable of type integer called
[Total] which holds 25, and another one as a string called [Message]
which holds "The Total is ## out of 100".
How can you convert the [Total] to a string to insert it in the string
[Message] in the position '##' so that the [Message] will contain "The
Total is 25 out of 100" as the final result?
Thanx in advance...
__ _________________________________
/ || Hashem Al-Dhaheri
/ O || hashem@dhaheri.demon.co.uk
/____|| ____ ___ ___ ___
/ || - / //__//__//__//__ /___) /
/ ||___ /___// // // //__ / \ /
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Types Converting
1996-04-27 0:00 Types Converting HSR Al-Dhaheri
@ 1996-04-27 0:00 ` Joerg Rodemann
1996-04-27 0:00 ` Robert A Duff
0 siblings, 1 reply; 3+ messages in thread
From: Joerg Rodemann @ 1996-04-27 0:00 UTC (permalink / raw)
HSR Al-Dhaheri (hashem@dhaheri.demon.co.uk) wrote:
> Hi,
> I would like to know how can you convert an integer to a string in Ada.
> For example, if you've declared a variable of type integer called
> [Total] which holds 25, and another one as a string called [Message]
> which holds "The Total is ## out of 100".
> How can you convert the [Total] to a string to insert it in the string
> [Message] in the position '##' so that the [Message] will contain "The
> Total is 25 out of 100" as the final result?
Hello!
The easiest solution is:
Message : String;
Message := "The Total is " & i'Image & " out of 100";
Have a nice day
George
--
Joerg 'George' Rodemann Erhard-Groezinger-Strasse 82
Department of Physics D-89134 Blaustein
University of Ulm Tel. (0731) 553319
e-mail: rodemann@mathematik.uni-ulm.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Types Converting
1996-04-27 0:00 ` Joerg Rodemann
@ 1996-04-27 0:00 ` Robert A Duff
0 siblings, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1996-04-27 0:00 UTC (permalink / raw)
In article <4ltn0h$c37@rigel.rz.uni-ulm.de>,
Joerg Rodemann <rodemann@mathematik.uni-ulm.de> wrote:
> Message : String;
It's illegal to declare a variable of type String, unless you either
initialize it, or give bounds. E.g. "Message: String := ...;" or
"Message: String(1..50);".
> Message := "The Total is " & i'Image & " out of 100";
Image is an attribute of types, not variables. E.g. "Integer'Image(I)".
What you want is something like:
Message: constant String := "The total is" & Integer'Image(I)
& " out of 100";
Note that the 'Image attribute evilly adds an extra space (if I is
positive), so I didn't put a space after "is".
In my own code, I write an Image function, which avoids the annoying
extra space, and has lots of options like allowing hexadecimal, and
putting in underscores every 3 characters, etc. All with defaults, of
course, so "Image(I)" does something reasonable.
- Bob
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1996-04-27 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-27 0:00 Types Converting HSR Al-Dhaheri
1996-04-27 0:00 ` Joerg Rodemann
1996-04-27 0:00 ` Robert A Duff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox