Strings

Strings are declared by using single or double quotes. The difference is not so important for now. In our Hello World example the 'Hello, world!' was a string.

say 'foo'

Basic string operators and functions

Strings can be concatenated (glued) using a . operator.

say 'foo' . 'bar'

With operator x you can repeat the strings.

say 'foo' x 3;

Usually you would want to manipulate strings in order to get their lengths, find a symbol or a substring and so on. Basic string manipulation functions include length(), substr(), index(), rindex().

say length 'foo';
say substr 'foo', 1, 2;
say index 'foo', 'o';
say rindex 'foo', 'o';

Exercise

Print out the position of string 'ball' in string 'Football'.

say