Chapter 5 : Strings

Concatenating Strings

Strings can be concatenated using the ++ operator.


Slicing Strings

Strings can be sliced using a built-in function String.sub which takes three parameters: – an offset describing the index of first character that will be copied – the length describing the number of characters that will be copied (starting from the given offset) – the string being sliced

The function String.sub can be used as follows:


⚠️ Notice that the offset and length of the sub function are natural numbers.

Length of Strings

The length of a string can be found using a built-in function String.length as follows:


Your mission

1 – Reassign my_ship by modifying the engine attribute (third number) from 0 to 1. Use substrings for the attributes before and after to make sure they are untouched.