Reputation: 1500
I am getting input from user using Get_Line
,
String can be a command followed by a value (command --- one or more white spaces --- value -- new line)like,
CMD 4
CMD 6
CMD 10
How can i parse command and value in individual variables ?
so far i can parse string before spaces as, but after space how can i get value and convert it in integer ?
for I in ip'Range loop
if ip(I) = ' ' or ip(I) = HT then
Put_Line(CMD);
Put_Line(Integer'Image(Index));
else
CMD(I) := ip(I);
Index := Index+1;
end if;
end loop;
--
Thanks
Upvotes: 0
Views: 1114
Reputation: 6601
with Ada.Text_IO;
procedure Simple_Command_Parser_1 is
type Commands is (CMD);
type Values is range 4 .. 10;
package Command_Text_IO is new Ada.Text_IO.Enumeration_IO (Commands);
package Value_Text_IO is new Ada.Text_IO.Integer_IO (Values);
Command : Commands;
Value : Values;
begin
loop
Command_Text_IO.Get (Command);
Value_Text_IO.Get (Value);
Ada.Text_IO.Skip_Line;
end loop;
end Simple_Command_Parser_1;
Upvotes: 2