Strings. Overview

A string is a list (or sequence) of characters in a particular order. The entire sequence of characters is treated as a single entity.

A character is anything you can type on the keyboard with a single keystroke (letter, number, backslash, or some other character).
Strings can have spaces: "Hello world!".
An empty string is a string that has 0 characters.
Pascal recognizes as strings everything written in apostrophes (' ').
In Pascal, a string is of type string.

You can write a new value to a string using the input statement
read(s);
You can also simply assign a string value to the variable, such as  
s := 'Python';
You can determine the length of a string using the built-in function length
n := length(s)


String comparison

Strings can be compared to each other just like numbers. You can determine which of the lines is greater, which is less.

When comparing strings, character codes are compared. There are dozens, if not hundreds, of character encodings. The easiest way to understand this concept is to understand one of the simplest, ASCII (read here).  ;
It is necessary to understand that in modern encodings both Russian and English letters are arranged in alphabetical order, the numbers also go from smaller to larger. 
For example, in the ASCII code table, the code for the English letter 'A' - 65, letters 'a' - 97, digit '0' has code 48. Russian letters are located in the extended part of the ASCII code table (numbers from 128 to 255). Capital letters come before (i.e. have a smaller code) than lowercase letters.
In most of the encoding tables used, the patterns are the same, lowercase letters are later than uppercase letters, numbers are earlier than letters, and Russian letters are later than English ones.

For example: "locomotive"  < "steamboat", because the words differ in the fifth letter and "in" < "x".

Unfortunately, there is no function in Pascal that would allow reading multiple space-separated lines from a single line. To do this, you have to write your own function:
vars, w: string;
i, j, ind: integer;
a: array of string;

begin
    readln(s);
    setlength(a, length(s));
    i := 1;
    ind := 0;
    while i < length(s) do
    begin
        while (i < length(s)) and ('' + s[i] = ' ') do i += 1;
        j := i + 1;
        w := '' + s[i];
        while (j < length(s)) and ('' +s[j] <> ' ') do begin
            w += s[j];
            j += 1;
        end;
        a[ind] := w;
        ind += 1;
        i := j;
    end;
    write(a[0], a[1]);
end.

As a result, we get an array of strings.

Strings can be added together using the "+" sign. This operation is called string concatenation or concatenation
For example, 
s := 'Hi, ';
s1 := 'world';
writeln(s + s1);
The screen will display the phrase "Hello world" (without quotes).

Referencing row indices
Each character of a string has its own number (called index), and indexing in the programming language Pascal starts from one. That is, the first character has index 1, the second has index 2, and so on.
String characters can be accessed by indexes, which are indicated in square brackets s[i].
 
Example 
String S H e l l o
Index S[1] S[2] S[3] S[4] S[5]

P.S. Many string methods in PascalABC.NET assume that strings are indexed from zero. We won't be using string methods that work with zero-based indexes for the time being. There are equivalent replacements for these with external functions that assume that rows are indexed from 1. 
 

Since a character can be accessed by index, you can use a variable loop to iterate over all characters, which will take on possible index values. For example, a program that displays all the character codes of the string s would look like this
for i := 1 to length(s) do
    writeln(s[i], ord(s[i]))
Explanations for the program:
1) The length(s) function finds the length of a string. The index of the first character is 1 and the index of the last is length(s). The loop variable i will just take values ​​from 1 to length(s).
2) In each line, the symbol itself will be displayed first, and then its code, which is returned by the built-in function ord()

The same enumeration can be written shorter:
for c in s do 
    writeln(c, ord(c));
In this fragment, the loop header loops through all the characters s, placing them in turn in the variable c.

The peculiarity of Pascal when working with strings is that strings are mutable objects. In other words, we can change individual characters of a string.
For example, the following statement will work
s[5] := 'a';
You can also compose a new string from the characters with the required changes.
For example, a program that replaces all characters 'a' to characters 'b' will look like this:
read(s);
    for i := 1 to length(s) do begin
        if s[i] = 'a'then s[i] := 'b';
    end;
writeln(s);
In this example, we loop through all the characters of the string s. In the body of the loop, we check the value of the variable s[i]: if the character matches the character 'a', then we replace it with 'b'.