Array Slices
Array Slices
- A range can be used in place of an array index to specify a portion of an array
- The portion of the array is called an array slice
Array Slices - Compare These Two Statements
declare
s: String := "Hi Mom!";
begin
put_line(s(4..7) & s(1..2));
What output does this produce?
Is this what we want?
If not, how to fix?
Array Slices - Compare These Two Statements
declare
s: String := "Hi Mom!";
begin
put_line(s(4..7) & s(3..3) & s(1..2));
put_line(s(4..7) & s(3) & s(1..2));
What would s(4..3)
represent
- How else could this be written?
Array Slice - Example
Array Slices and Unconstrained Arrays
- We can gain flexibility by passing a slice
to a parameter that's an unconstrained array
- Example: slicedemo2.adb and prettified