* String Segment to Integer Question
@ 1997-09-28 0:00 David Conly
1997-09-29 0:00 ` Richard A. O'Keefe
0 siblings, 1 reply; 2+ messages in thread
From: David Conly @ 1997-09-28 0:00 UTC (permalink / raw)
Hey All:
Is there any way to take a portion of a string inputed by the user at the keyboard and make it
into an integer. I need the user to enter a string such as "8h32" and be able to extract the 8 and the
32 from it separately. Currently I'm writing the string to a file and then reading the first number,
skipping the second, and then reading the last 2 digits. Can I perform this operation without having to
write to a file? Any input is welcome!
Thanks,
David Conly
conly@cs.und.edu
------------------------------------------------------------------------------
David C. Conly | Flying. One part aptitude, one
| part altitude, and two parts
conly@cs.und.edu | attitude.
http://www.cs.und.edu/~conly | FLYING MAGAZINE
------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: String Segment to Integer Question
1997-09-28 0:00 String Segment to Integer Question David Conly
@ 1997-09-29 0:00 ` Richard A. O'Keefe
0 siblings, 0 replies; 2+ messages in thread
From: Richard A. O'Keefe @ 1997-09-29 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1606 bytes --]
David Conly <conly@cs.und.edu> writes:
>Is there any way to take a portion of a string inputed by the user at
>the keyboard and make it into an integer.
The keyboard has nothing to do with it.
with Ada.Text_IO, Ada.Integer_Text_IO;
procedure Demo is
procedure Use_Value(S: in String; H: out Integer; M: out Integer) is
-- Precondition:
-- S = "H" & "h" & "MN" for some digits H, M, N.
-- Postcondition:
-- H = "H" as an integer
-- M = "MM" as an integer
-- Method:
-- Uses standard <integer type>'Value attribute.
begin
H := Integer'Value(S(1..1));
M := Integer'Value(S(3..4));
end Use_Value;
procedure Use_Get(S: in String; H: out Integer; M: out Integer) is
-- Interface:
-- same as Use_Value
-- Method:
-- Uses Ada.Integer_Text_IO.Get from a string.
Last: Positive;
begin
Ada.Integer_Text_IO.Get(S(1..1), H, Last);
Ada.Integer_Text_IO.Get(S(3..4), M, Last);
end Use_Get;
procedure Show_Result(S: in String; H, M: in Integer) is
begin
Ada.Text_IO.Put('(');
Ada.Integer_Text_IO.Put(H, Width => 1);
Ada.Text_IO.Put(',');
Ada.Integer_Text_IO.Put(M, Width => 2);
Ada.Text_IO.Put(") <= '");
Ada.Text_IO.Put(S);
Ada.Text_IO.Put_Line("'.");
end;
S: constant String := "8h32";
H, M: Integer;
begin
Use_Value(S, H, M);
Show_Result(S, H, M);
Use_Get(S, H, M);
Show_Result(S, H, M);
end Demo;
--
John �neas Byron O'Keefe; 1921/02/04-1997-09-27; TLG,TLTA,BBTNOTL.
Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-09-29 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-28 0:00 String Segment to Integer Question David Conly
1997-09-29 0:00 ` Richard A. O'Keefe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox