如何在 Ada 中重新索引字符串?

问题描述 投票:0回答:1

我在重新索引切片字符串时遇到问题,

    procedure String_Test is

      mystr:String:="Hello World";
      str:String:=mystr(6 .. 11);
      str_re_indexed:String:=Trim(Str, Left); -- it works but whitespace is removed

   begin
      
      for K in str_re_indexed'First .. str_re_indexed'Last loop
         Put_Line(Integer'Image(K));
      end loop;

   end String_Test;

重新索引后,字符串应为 (1 ..6)
有没有预定义的函数可以做到这一点?

string ada
1个回答
0
投票

您可以为此定义一个字符串子类型:

subtype String_1_6 is String (1 .. 6);
Result : String := String_1_6 (My_Str);
© www.soinside.com 2019 - 2024. All rights reserved.