A STRING is used when you want to represent a sequence of characters as a single unit of data.
Examples are:
max_str_length : constant := 26; alphabet, response : STRING (1 .. max_str_length);
literals:
alphabet := "abcdefghijklmnopqrstuvwxyz"; response := alphabet;
Concatenation (&)
alphabet(1..3) & alphabet(26..26) = "abcz" PUT("The alphabet is " & alphabet & '.');
individual character: specify position
alphabet(10) 'j' alphabet(17) 'q'
slice: specify range of positions
alphabet(20..23) "tuvw" alphabet(4..9) "defghi"
assign to compatible slice
response(1..4) := "FRED"; response "FREDefghijklmnopqrstuvwxyz"
slice with equal bounds: STRING of one character
response(1..1) "F" (not the same as 'F')
An example program shows the use of slices to manipulate parts of strings.
A second example shows how the same thing can be achieved using both slices and concatenation.
TEXT_IO
Output: PUT, PUT_LINE
GET(a_string);
GET_LINE(a_string, n);
An example program shows the use of GET for numbers and GET_LINE for strings.