Pascal has many routines for working with strings. Many of them are called using dot notation and are called methods. A complete list of string manipulation methods can be found online.
Let's get acquainted with some of them.
s := 'aAbBcC'
sUp := uppercase(s); // sUp = "AABBCC" - a method that converts each character of a string to uppercase
sLow := lowercase(s) //
sLow = "aabbcc" - a method that converts each character of a string to lowercase
The method is always written with parentheses. There are some parameters inside the brackets, if they are needed.
Another useful method - val
(s, v, ind)
- method to check if all characters of a string are digits.
s - source string,
v contains a number if the source string was a number, and 0 otherwise,
ind contains the number of the first
index s which is not a digit, or 0 if s
is a number.
s := 'ab1c'
val(s, v, ind);
writeln(v, ' ', ind); // 0 3
s := '123';
val(s, v, ind);
w(vriteln, ' ', ind); // 123 0
The useful trim(s) - method allows you to remove spaces at the beginning and end of a string
s := ' ab 1c ';
print('s=', trim(s)); // s=ab 1c