ada中insert的使用?

发布于 2024-09-05 21:33:58 字数 87 浏览 3 评论 0原文

谁能告诉我 Ada 语言中 Insert 的用法。我尝试过网络,但我无法弄清楚。如果有人也能为我提供示例,那将是一个很大的帮助。

提前致谢 麦迪

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北凤男飞 2024-09-12 21:33:58

我以前从未使用过 Insert (除了使用字符串进行简单的 Put_Line 之外,通常不需要执行任何操作),因此将其组合在一起:

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;

输出是

       |        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

我希望给出的味道一般。

Ada95AARM A.4.3 位于 http://www. adaic.com/standards/95aarm/html/AA-A-4-3.html (3) 讲述了这背后的概念。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文