In Pascal, you can select part of a string (substring). For this, the copy operation is used.
The general form of the operation is as follows:
s1 := copy(s, index, count);
This command takes a slice from the string
s
, starting at the character at index
index of length count.
For example,
s1 := copy(s, 3, 5);
If index is greater than the length of the string, then an empty string is returned. If count characters, starting at index, are longer than the length of the string, then the string s is returned, starting at index and ending.
And here's how easy it is to reverse a string:
s := '0123456789';
s1 := reverseString(s); // s1 = '0123'