Working with strings and symbols

Although computers take their name from the verb "compute", they are equally successful in processing not only numbers but also any unstructured information, the most famous example of which is text. In MQL programs, text is also used everywhere, from the names of the programs themselves to comments in trade orders. To work with the text in MQL5, there is a built-in string type, which allows you to operate on character sequences of arbitrary length.

To perform typical actions with strings, the MQL5 API provides a wide range of functions that can be conditionally divided into groups according to their purpose, such as string initialization, their addition, searching and replacing fragments within strings, converting strings to character arrays, accessing individual characters, as well as formatting.

Most of the functions in this chapter return an indication of the execution status: success or error. For functions with result type bool, true is usually a success, and false is an error. For functions with result type int a value of 0 or -1 can be considered an error: this is stated in the description of each function. In all these cases, the developer can find out the essence of the problem. To do this, call the GetLastError function and get the specific error code: a list of all codes with explanations is available in the documentation. It's important to call GetLastError immediately after receiving the error flag because calling each following instruction in the algorithm can lead to another error.