Программирование постоянно связано с работой с some data, in particular, with strings. The string operator is set the same in most languages, including Pascal: string. But Pascal has its own characteristics and properties that you need to know before you begin.
Before Understanding the Syntaxstring data type in Pascal, it should be understood that may be a string. In fact, in Pascal a string is an array of characters, each of which can be any element from an ASCII table. That is, any letter, number, punctuation mark or space can be used as a string.
Maximum number of characters per linemakes 255 units, and each of them receives the corresponding sequence number. Therefore, if you need to write large text into a variable, you should create an array of string. Pascal will correctly process this request, and it will be possible to save much longer text data.
For strings is the String type.Pascal allows the programmer to specify the exact number of characters or to leave its length by default - in this case it will be equal to 255. To declare a string variable, listing the same arguments, you must enter the keyword after the colon - string and, if necessary, specify the length in square brackets lines. In the example below, the string is "str", 10 characters long:
var str: string [10].
In the code of the Pascal string program, you can specify any values - for this it is only necessary to enclose them in single quotes.
Depending on the language, the number of operations the string can work with is determined. Pascal allows you to compare and merge string data.
Merge operation (in other words concatenationor concatenation) is performed to combine multiple lines into one. It is implemented using the addition sign: "+". With it, you can build a single line consisting of a series of expressions, constants and variables.
It is worth noting that when combining words insentence by concatenating strings, there will be no space between each element. Therefore, wanting to get a well-built structure, you should clearly indicate the presence of a gap in the right places by adding a space character, for example, like: "".
Another operation supported in Pascal is string compare or string comparison. It also uses the simplest mathematical signs:
The result of the relation operation is the return of a boolean true or false.
String comparison is performed character by character, andfinding the first inconsistency result will be determined according to the coding table. So, when figuring out which row is larger, at the position where there will be different characters, the code in this table will be compared, and the result will determine the answer that the operation returns.
As in any programming language, in PascalThere are a number of functions with which a string can be used. Pascal allows you to copy a part of a variable, combine several lines together, find a substring and calculate its length. This is done using the following 4 functions:
Copy (S, poz, n) - here S is a string variable, and poz and n are integer.
Concat (s1, s2 ...).
Length (str).
Pos (subS, S).
There are only two standard procedures used in Pascal. The first allows you to remove some substring, and the second - insert a row of characters into the string.
So, the Delete procedure deletes from the selected line, from the specified position, a substring from a certain number of characters. Each of these parameters is an argument of this operation:
Do it (With, pos, n).
And insert a sequence of characters in the stringYou can use the Insert. The procedure has as its parameters three values — a substring, a string, and a position from which the characters will be inserted:
Insert (subS, S, poz).
When performing tasks, often have to changetype of variables. Consider, for example, how to convert a string to an integer. Pascal does not allow adding the numbers written in the string, therefore, to produce a sum, their type must be changed. There are special procedures for this: