ComputersProgramming

Delphi pos - lines in Pascal

In Delphi, as in any other programming language, you can work with strings. There are many functions for working with them. In this article, we'll look at 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 string we are looking for, the string we are looking for). For example, in the word "machine" we need to find the letter "O". Write pos ('o', 'Automatic'). During the execution of the program, the figure 4 appears in place of this function. Since the letter O in the word "automatic machine" is on the 4th place. Or we want to find a whole segment of symbols. In the word "Refrigerator" find "dile". Pos ('dil', 'refrigerator'). It will return to us 5, since the excerpt starts from the 5th character. If the character or a line of characters in the source line does not exist at all, then the function returns 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.

Other functions in Delphi

In addition to the pos function, Delphi includes many functions for working with strings. For example, the function copy. It is used to copy a single section from one line to another. Also, the concat function serves as a two-line concatenator. As in mathematics two numbers are added, lines are also joined together.

String procedures in Delphi

Functions always return something, but procedures do not. An example of a string procedure is the insertion and deletion procedures. The Delete procedure can remove fragments from a string. And Insert - insert. Skillfully combining these procedures, and using functions, you can achieve great results, for example, all error correctors that emphasize incorrectly written words, and also correct them, translators, dictionaries and so on, work. They all use string functions, but probably not in Pascal. Knowing string functions and procedures, you can, for example, write the program shown in the figure above.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.