Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It can be done, but the mechanisms are a bit cumbersome and quite a bit more verbose.<br> What I would generally do is write separate procedures to handle your more complicated output, e.g. dates and use that with the rest of the string handling for clarity.</p> <pre><code>package Integer_IO is new Ada.Text_IO.Integer_IO (Integer); procedure Output_Date ( Day : in Integer; Month: in Integer; Year: in Integer) is begin Integer_IO.Put(Item =&gt; Day, Width =&gt; 2); Text_IO.Put("-"); Integer_IO.Put(Item =&gt; Month, Width =&gt; 2); Text_IO.Put("-"); Integer_IO.Put(Item =&gt; Year, Width =&gt; 4); end Output_Date; procedure Output_String ( Item : in String; Width : in Integer; Separator : in String := "|"; Truncate : Boolean := False) is Field_Index : Integer := Text_IO.Col; begin if Item'length &gt; Width and Truncate then Text_IO.Put(Item(1..Width) &amp; Separator); else Text_IO.Put(Item) &amp; Separator; end if; Text_IO.Set_Col ( Field_Index + Width + 1 ); end Output_String; </code></pre> <p>This will enforce fixed length fields, which will optionally allow truncation of long strings, or else move subsequent entries onto the next line. Set_Col will set the line position for the next write, potentially placing it on the next line if the current write position has already exceeded the one requested. </p> <p>I threw string truncation in there as a chance to use array slicing and Text_IO's output manipulation, but I'm not generally a fan of default truncation, as allowing the string to overrun the requested width or indenting on the next line tend make formatting errors more obvious.</p> <p>So printing out something like your first line, given the code above, might look something like: </p> <pre><code>Name : String := "Ashley" Phone : String := "01033438392" Address: String := "Wellington, New Zealand" Day : Integer := 14; Month : Integer := 4; Year : Integer := 1987; Output_String(Item=&gt; Name, Width =&gt; 10); Output_String(Item=&gt; Phone, Width =&gt; 11); Output_String(Item=&gt; Address, Width =&gt; 20); Output_Date(Day,Month,Year); </code></pre> <p>Text IO in Ada is usually cumbersome, but generally has the virtue of making what you are doing relatively clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload