There are helper tools for this particular format setting.
procedure Put(Item : in Num; Width : in Field := Default_Width; Base : in Number_Base := Default_Base);
Puts a field with Item aligned to the right and white character as a filler. Where Width is the width of the field, and Base is like defualt.
function Head (Source : in String; Count : in Natural; Pad : in Character := Space) return String; function Tail (Source : in String; Count : in Natural; Pad : in Character := Space) return String;
Returns a formatted string. Where Count is the width of the field, and Pad is the filler for the field. Head aligns the line to the left. Tail aligns the string to the right.
Let the column width be 8 characters long and use a dash as a placeholder.
Put_Line (Head ("Ashley", 8, '-')); Put_Line (Head ("Aloha", 8, '-')); Put_Line (Head ("Jack", 8, '-')); Put_Line (Tail ("Ashley", 8, '-')); Put_Line (Tail ("Aloha", 8, '-')); Put_Line (Tail ("Jack", 8, '-'));
Exit
Ashley
Discrete_type attribute 'Width
Returns the length that the discrete type requires to be represented as text.
Example
with Ada.Text_IO; use Ada.Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Calendar; use Ada.Calendar; procedure Test is subtype Index is Positive range 95 .. 1223; procedure Put_Line ( I : in out Index; Name : String; Phone : Natural; Address : String; T : in out Time ) is begin Put (I, Index'Width); Put (": "); Put (Head (Name, 10, ' ')); Put (" | "); Put (Tail (Phone'Img (Phone'Img'First + 1 .. Phone'Img'Last), 13, '0')); Put (" | "); Put (Head (Address, 20, ' ')); Put (Year (T), Year_Number'Width); Put ("-"); Put (Month (T), Month_Number'Width); Put ("-"); Put (Day (T), Day_Number'Width); I := Positive'Succ (I); T := T + Duration (60 * 60 * 24 * 3); New_Line; end; I : Index := Index'First; Now : Time := Clock; begin Put_Line (I, "Ashley", 1033438392, "Wellington, New Zealand", Now); Put_Line (I, "Aloha", 01087651234, "Hawaii, United States of America", Now); Put_Line (I, "Jack", 01082840184, "Beijing, China", Now); I := Index'Last - 3; Put_Line (I,"Ashley", 1033438392, "Wellington, New Zealand", Now); Put_Line (I,"Aloha", 01087651234, "Hawaii, United States of America", Now); Put_Line (I,"Jack", 01082840184, "Beijing, China", Now); end;
Exit
95: Ashley | 0001033438392 | Wellington, New Zeal 2015- 5- 24 96: Aloha | 0001087651234 | Hawaii, United State 2015- 5- 27 97: Jack | 0001082840184 | Beijing, China 2015- 5- 30 1220: Ashley | 0001033438392 | Wellington, New Zeal 2015- 6- 2 1221: Aloha | 0001087651234 | Hawaii, United State 2015- 6- 5 1222: Jack | 0001082840184 | Beijing, China 2015- 6- 8
I would recommend creating a type for a phone number, I donβt know if it should be a string or a number with heading numbering, the phone number can have different lengths, I think.