いくつかのオプションがあります。
- 整数値が常に負でないことがわかっている場合は、文字列をスライスして先頭の空白を省略することができます。
- Ada.Strings.Fixed.Trim()関数を使用して、空白を削除できます。
- Put()プロシージャは、Ada.Text_IO.Integer_IOインスタンス化(インスタンス化されたAda.Integer_Text_IOなど)から使用できます。
説明するコードは次のとおりです。
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Strings.Fixed;
procedure Int_Image is
use Ada.Text_IO;
use Ada.Integer_Text_IO;
use Ada.Strings.Fixed;
N : Integer := 20;
Raw_Image : constant String := Integer'Image(N);
Trimmed_Image : constant String := Trim(Raw_Image, Ada.Strings.Left);
Sliced_Image : constant String := Raw_Image(2 .. Raw_Image'Last);
begin
Put_Line("Raw 'image :" & Raw_Image & ":");
Put_Line("Trimmed image :" & Trimmed_Image & ":");
Put_Line("Sliced image :" & Sliced_Image & ":");
Put ("'Put' image :");
Put (N, Width => 0);
Put_Line(":");
end Int_Image;
これをGNATでコンパイルして実行すると、次のようになります。
$./int_image
Raw 'image : 20:
Trimmed image :20:
Sliced image :20:
'Put' image :20: