Previous topic | Ada Home Page | Index

Substring example

Program


-------------------------------------------------
-- Skansholm page 83
-- Convert date formats
-- Example of slices
-------------------------------------------------

with TEXT_IO; use  TEXT_IO;

procedure translate_date is
 
    american_date : STRING (1..8);
    british_date  : STRING (1..8)  := "  /  /  ";
    ISO_date      : STRING (1..10) := "19  -  -  ";
 
begin
    PUT_LINE ("Enter date as mm/dd/yy");
    GET (american_date);

    british_date (1..2) := american_date (4..5);
    british_date (4..5) := american_date (1..2);
    british_date (7..8) := american_date (7..8);

    PUT_LINE ("The british form of the date is: ");
    PUT_LINE (british_date);

    ISO_date (3.. 4) := american_date (7..8);
    ISO_date (6.. 7) := american_date (1..2);
    ISO_date (9..10) := american_date (4..5);

    PUT_LINE ("The ISO form of the date is: ");
    PUT_LINE (ISO_date);

end translate_date;


Program Execution

Enter date as mm/dd/yy
05/02/95
The british form of the date is:
02/05/95
The ISO form of the date is:
1995-05-02


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 12 Feb 96