Hi all,
Can anyone please tell me the usage of Insert in Ada language. I had tried the net but i couldn't just figure out. It would be a great help if anyone could provide me with examples too.
Thanks in advance Maddy
Hi all,
Can anyone please tell me the usage of Insert in Ada language. I had tried the net but i couldn't just figure out. It would be a great help if anyone could provide me with examples too.
Thanks in advance Maddy
I've never used Insert
before (don't often have to do anything but a simple Put_Line
with strings) so knocked this together:
with Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
procedure Inserting is
Base : constant String := (1 .. 8 => ' ') & "aaaaaaaa" & (1 .. 8 => ' ');
begin
Put_Line (ASCII.HT & '|' & Base & '|');
for J in 1 .. 24 loop
declare
S : String := Base;
begin
Ada.Strings.Fixed.Insert (S,
Before => J,
New_Item => "ccc");
Put_Line (Integer'Image (J) & ASCII.HT & '|' & S & '|');
end;
end loop;
end Inserting;
and the output is
| aaaaaaaa |
1 |ccc aaaaaaaa |
2 | ccc aaaaaaaa |
3 | ccc aaaaaaaa |
4 | ccc aaaaaaaa |
5 | ccc aaaaaaaa |
6 | ccc aaaaaaaa |
7 | ccc aaaaaaaa |
8 | ccc aaaaaaaa |
9 | cccaaaaaaaa |
10 | acccaaaaaaa |
11 | aacccaaaaaa |
12 | aaacccaaaaa |
13 | aaaacccaaaa |
14 | aaaaacccaaa |
15 | aaaaaacccaa |
16 | aaaaaaaccca |
17 | aaaaaaaaccc |
18 | aaaaaaaa ccc |
19 | aaaaaaaa ccc |
20 | aaaaaaaa ccc |
21 | aaaaaaaa ccc |
22 | aaaaaaaa ccc|
raised ADA.STRINGS.LENGTH_ERROR : a-strfix.adb:358
which I hope gives the general flavour.
The Ada95AARM A.4.3 at http://www.adaic.com/standards/95aarm/html/AA-A-4-3.html (3) tells about the concepts behind this.