Delphi pos - strings in Pascal

In Delphi, as in any other programming language, you can work with strings. There are many functions to work with them. In this article we will analyze the most popular string functions in Delphi.

Finding a character in a string

In Delphi, pos is used to find the position of a character or group of characters in a string. This function is used as follows: pos (the line we are looking for, the line we are looking for). For example, in the word “machine” we need to find the letter “O”. We write pos ('o', 'Automatic'). During program execution, the number 4 will appear in place of this function. Since the letter O in the word "machine" is in 4th place. Or we want to find a whole segment of characters. In the word “Refrigerator” find “Deal”. Pos ('del', 'refrigerator'). She will return us 5, since the excerpt starts from 5 characters. If there is no character or a segment of characters in the original string, then the function will return 0. It is also important to remember that the letters a and A are different, so if you need to find all the letters a in the word, then look for both a and A.

delphi pos

Other features in Delphi

In addition to the pos function, Delphi includes many functions for working with strings. For example, the copy function. It is used to copy a single section from one line to another. The concat function also serves as a stitcher of two lines. Just as two numbers add up in mathematics, the same way lines are connected together.

String procedures in Delphi

delphi string functions

Functions always return something, but procedures do not. An example of string procedures is insert and delete. The Delete procedure can remove fragments from a string. And Insert - insert. By skillfully combining these procedures, as well as using functions, you can achieve tremendous results, for example, all error correctors work that emphasize misspelled words, as well as correct them, translators, dictionaries, and more. They all use string functions, but probably not in Pascal. Knowing the string functions and procedures, you can, for example, write the program shown in the figure above.

Source: https://habr.com/ru/post/K22435/


All Articles