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".