Initial Commit.

This commit is contained in:
ZhijuCen
2026-06-23 21:47:51 +08:00
commit d17f68e979
5201 changed files with 318318 additions and 0 deletions
@@ -0,0 +1,25 @@
# String Functions
This is a group of functions intended for working with data of the [string](/en/docs/basis/types/stringconst) type.
| Function | Action |
| --- | --- |
| StringAdd | Adds a string to the end of another string |
| StringBufferLen | Returns the size of buffer allocated for the string |
| StringCompare | Compares two strings and returns 1 if the first string is greater than the second; 0 - if the strings are equal; -1 (minus 1) - if the first string is less than the second one |
| StringConcatenate | Forms a string of parameters passed |
| StringFill | Fills out a specified string by selected symbols |
| StringFind | Search for a substring in a string |
| StringGetCharacter | Returns the value of a number located in the specified string position |
| StringInit | Initializes string by specified symbols and provides the specified string length |
| StringLen | Returns the number of symbols in a string |
| StringSetLength | Sets a specified length (in characters) for a string |
| StringReplace | Replaces all the found substrings of a string by a set sequence of symbols |
| StringReserve | Reserves the buffer of a specified size for a string in memory. |
| StringSetCharacter | Returns a copy of a string with a changed value of a symbol in a specified position |
| StringSplit | Gets substrings by a specified separator from the specified string, returns the number of substrings obtained |
| StringSubstr | Extracts a substring from a text string starting from a specified position |
| StringToLower | Transforms all symbols of a selected string to lowercase |
| StringToUpper | Transforms all symbols of a selected string into capitals |
| StringTrimLeft | Cuts line feed characters, spaces and tabs in the left part of the string |
| StringTrimRight | Cuts line feed characters, spaces and tabs in the right part of the string |
@@ -0,0 +1,68 @@
# StringAdd
The function adds a substring to the end of a string.
```
bool  StringAdd(
   string&  string_var,        // string, to which we add
   string   add_substring      // string, which is added
   );
```
Parameters
string_var
[in][out]  String, to which another one is added.
add_substring
[in]  String that is added to the end of a  source string.
Return Value
In case of success returns true, otherwise false. In order to get an [error code](/en/docs/constants/errorswarnings/errorcodes), the [GetLastError()](/en/docs/check/getlasterror) function should be called.
Example:
```
void OnStart()
  {
   long length=1000000;
   string a="a",b="b",c;
//--- first method
   uint start=GetTickCount(),stop;
   long i;
   for(i=0;i<length;i++)
     {
      c=a+b;
     }
   stop=GetTickCount();
   Print("time for 'c = a + b' = ",(stop-start)," milliseconds, i = ",i);
 
//--- second method
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      StringAdd(a,b);
     }
   stop=GetTickCount();
   Print("time for 'StringAdd(a,b)' = ",(stop-start)," milliseconds, i = ",i);
 
//--- third method
   start=GetTickCount();
   a="a"; // re-initialize variable a
   for(i=0;i<length;i++)
     {
      StringConcatenate(c,a,b);
     }
   stop=GetTickCount();
   Print("time for 'StringConcatenate(c,a,b)' = ",(stop-start)," milliseconds, i = ",i);
  }
```
See also
[StringConcatenate](/en/docs/strings/stringconcatenate), [StringSplit](/en/docs/strings/stringsplit), [StringSubstr](/en/docs/strings/stringsubstr)
@@ -0,0 +1,45 @@
# StringBufferLen
The function returns the size of buffer allocated for the string.
```
int  StringBufferLen(
   string  string_var      // string
   )
```
Parameters
string_var
[in]  String.
Return Value
The value 0 means that the string is constant and buffer size can't be changed. -1 means that the string belongs to the client terminal, and modification of the buffer contents can have indeterminate results.
Example:
```
void OnStart()
  {
   long length=1000;
   string a="a",b="b";
//---
   long i;
   Print("before: StringBufferLen(a) = ",StringBufferLen(a),
         "  StringLen(a) = ",StringLen(a));
   for(i=0;i<length;i++)
     {
      StringAdd(a,b);
     }
   Print("after: StringBufferLen(a) = ",StringBufferLen(a),
         "  StringLen(a) = ",StringLen(a));
  }
```
See also
[StringAdd](/en/docs/strings/stringadd), [StringInit](/en/docs/strings/stringinit), [StringLen](/en/docs/strings/stringlen), [StringFill](/en/docs/strings/stringfill)
@@ -0,0 +1,74 @@
# StringCompare
The function compares two strings and returns the comparison result in form of an integer.
```
int  StringCompare(
   const string&  string1,                 // the first string in the comparison
   const string&  string2,                 // the second string in the comparison
   bool           case_sensitive=true      // case sensitivity mode selection for the comparison
   );
```
Parameters
string1
[in]  The first string.
string2
[in]  The second string.
case_sensitive=true
[in]  Case sensitivity mode selection. If it is true, then "A">"a". If it is false, then "A"="a". By default the value is equal to true.
Return Value
- -1 (minus one), if string1<string2
- 0 (zero), if string1=string2
- 1 (one), if string1>string2
Note
The strings are compared symbol by symbol, the symbols are compared in the alphabetic order in accordance with the current code page.
Example:
```
void OnStart()
  {
//--- what is larger - apple or home?
   string s1="Apple";
   string s2="home";
 
//--- compare case sensitive 
   int result1=StringCompare(s1,s2);
   if(result1>0) PrintFormat("Case sensitive comparison: %s > %s",s1,s2);
   else
     {
      if(result1<0)PrintFormat("Case sensitive comparison: %s < %s",s1,s2);
      else PrintFormat("Case sensitive comparison: %s = %s",s1,s2);
     }
 
//--- compare case-insensitive
   int result2=StringCompare(s1,s2,false);
   if(result2>0) PrintFormat("Case insensitive comparison: %s > %s",s1,s2);
   else
     {
      if(result2<0)PrintFormat("Case insensitive comparison: %s < %s",s1,s2);
      else PrintFormat("Case insensitive comparison: %s = %s",s1,s2);
     }
/* Result
     Case-sensitive comparison: Apple < home
     Case insensitive comparison: Apple < home
*/
  }
```
See also
[String Type](/en/docs/basis/types/stringconst), [CharToString()](/en/docs/convert/chartostring), [ShortToString()](/en/docs/convert/shorttostring), [StringToCharArray()](/en/docs/convert/stringtochararray), [StringToShortArray()](/en/docs/convert/stringtoshortarray), [StringGetCharacter()](/en/docs/strings/stringgetcharacter), [Use of a Codepage](/en/docs/constants/io_constants/codepageusage)
@@ -0,0 +1,61 @@
# StringConcatenate
The function forms a string of passed parameters and returns the size of the formed string. Parameters can be of any type. Number of parameters can't be less than 2 or more than 64.
```
int  StringConcatenate(
   string&  string_var,   // string to form
   void argument1         // first parameter of any simple type
   void argument2         // second parameter of any simple type
   ...                    // next parameter of any simple type
   );
```
Parameters
string_var
[out]  String that will be formed as a result of concatenation.
argumentN
[in]  Any comma separated values. From 2 to 63 parameters of any simple type.
Return Value
Returns the string length, formed by concatenation of parameters transformed into string type. Parameters are transformed into strings according to the same rules as in [Print()](/en/docs/common/print) and [Comment()](/en/docs/common/comment).
Example:
```
void OnStart()
  {
//--- declare and define variables participating in concatenation
   string text="";
   string text1="This script shows how the StringConcatenate() function works.\n";
   string text2="This is the second line, at the end of which there is a line break control code.\n";
   string text3="This is line number ";
   int    num3=3;
   string text31=", the number of which is entered into the function as a separate parameter.";
   string textN="\n";
   string text4="This is line number 4, preceded by a separate parameter with a line break code.";
   int    length=StringConcatenate(text, text1, text2, text3, num3, text31, textN, text4, "\nLine 5 includes a real number: ", 0.12345);
   Print(text, "\nLength of the resulting string = ", length);
   
   /*
   Result
   This script shows how the StringConcatenate() function works.
   This is the second line, at the end of which there is a line break control code.
   This is line number 3, the number of which is entered into the function as a separate parameter.
   This is line number 4, preceded by a separate parameter with a line break code.
   Line 5 includes a real number: 0.12345
   Length of the resulting string = 358
   */
  }
```
See also
[StringAdd](/en/docs/strings/stringadd), [StringSplit](/en/docs/strings/stringsplit), [StringSubstr](/en/docs/strings/stringsubstr)
@@ -0,0 +1,51 @@
# StringFill
It fills out a selected string by specified symbols.
```
bool  StringFill(
   string&   string_var,       // string to fill
   ushort    character         // symbol that will fill the string
   );
```
Parameters
string_var
[in][out]  String, that will be filled out by the selected symbol.
character
[in]  Symbol, by which the string will be filled out.
Return Value
In case of success returns true, otherwise - false. To get the [error code](/en/docs/constants/errorswarnings/errorcodes) call [GetLastError()](/en/docs/check/getlasterror).
Note
Filling out a string at place means that symbols are inserted directly to the string without transitional operations of new string creation or copying. This allows to save the operation time.
Example:
```
void OnStart()
  {
   string str;
   StringInit(str,20,'_');
   Print("str = ",str);
   StringFill(str,0);
   Print("str = ",str,": StringBufferLen(str) = ", StringBufferLen(str));
  }
// Result
//   str = ____________________
//   str =  : StringBufferLen(str) = 20
//
```
See also
[StringBufferLen](/en/docs/strings/stringbufferlen), [StringLen](/en/docs/strings/stringlen), [StringInit](/en/docs/strings/stringinit)
@@ -0,0 +1,136 @@
# StringFind
Search for a substring in a string.
```
int  StringFind(
   string  string_value,        // string in which search is made
   string  match_substring,     // what is searched
   int     start_pos=0          // from what position search starts
   );
```
Parameters
string_value
[in]  String, in which search is made.
match_substring
[in]  Searched substring.
start_pos=0
[in]  Position in the string from which search is started.
Return Value
Returns position number in a string, from which the searched substring starts, or -1, if the substring is not found.
Example:
```
#define   RESERVE    100
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get the symbol base currency and the profit currency
   string symbol_currency_base  =SymbolInfoString(Symbol(), SYMBOL_CURRENCY_BASE);
   string symbol_currency_profit=SymbolInfoString(Symbol(), SYMBOL_CURRENCY_PROFIT);
   PrintFormat("Symbol Currency Base: %s\nSymbol Currency Profit: %s", symbol_currency_base, symbol_currency_profit);
   
//--- in the loop through all symbols available on the server
   int total=SymbolsTotal(false), pos=-1;
   for(int i=0; i<total; i++)
     {
      //--- get the name of the next symbol
      string name=SymbolName(i, false);
      
      //--- look for a substring in the symbol name with the name of the base currency and
      //--- if a substring is found, display the symbol name, its index in the currency list and the name of the searched currency in the log
      pos = StringFind(name, symbol_currency_base);
      if(pos >= 0)
         PrintFormat("The '%s' symbol at index %u in the list contains the '%s' currency. Substring position in the symbol name: %d", name, i, symbol_currency_base, pos);
         
      //--- look for a substring in the symbol name with the name of the quoted currency and
      //--- if a substring is found, display the symbol name, its index in the currency list and the name of the searched currency in the log
      pos = StringFind(name, symbol_currency_profit);
      if(pos >= 0)
         PrintFormat("The '%s' symbol at index %u in the list contains the '%s' currency. Substring position in the symbol name: %d", name, i, symbol_currency_profit, pos);
     }
      
   /*
   Result
   StringFind (EURUSD,D1)   Symbol Currency Base: EUR
   StringFind (EURUSD,D1)   Symbol Currency Profit: USD
   The 'EURUSD' symbol at index 0 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURUSD' symbol at index 0 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'GBPUSD' symbol at index 1 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDCHF' symbol at index 2 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDJPY' symbol at index 3 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCNH' symbol at index 4 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRUB' symbol at index 5 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'AUDUSD' symbol at index 6 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'NZDUSD' symbol at index 7 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDCAD' symbol at index 8 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDSEK' symbol at index 9 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDHKD' symbol at index 10 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDSGD' symbol at index 11 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDNOK' symbol at index 12 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDDKK' symbol at index 13 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDTRY' symbol at index 14 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDZAR' symbol at index 15 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCZK' symbol at index 16 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDHUF' symbol at index 17 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDPLN' symbol at index 18 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRUR' symbol at index 19 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURAUD' symbol at index 27 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCAD' symbol at index 28 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCHF' symbol at index 29 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCZK' symbol at index 30 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURDKK' symbol at index 31 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURGBP' symbol at index 32 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURHKD' symbol at index 33 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURHUF' symbol at index 34 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURJPY' symbol at index 35 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURNOK' symbol at index 36 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURNZD' symbol at index 37 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURPLN' symbol at index 38 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURRUR' symbol at index 39 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURRUB' symbol at index 40 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURSEK' symbol at index 41 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURTRY' symbol at index 42 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURZAR' symbol at index 43 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'XAUUSD' symbol at index 47 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XAUEUR' symbol at index 48 in the list contains the 'EUR' currency. Substring position in the symbol name: 3
   The 'XAGUSD' symbol at index 50 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XAGEUR' symbol at index 51 in the list contains the 'EUR' currency. Substring position in the symbol name: 3
   The 'USDCRE' symbol at index 53 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'XPDUSD' symbol at index 65 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XPTUSD' symbol at index 66 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDGEL' symbol at index 67 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDMXN' symbol at index 68 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURMXN' symbol at index 69 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDCOP' symbol at index 75 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDARS' symbol at index 76 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCLP' symbol at index 77 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURSGD' symbol at index 89 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDILS' symbol at index 95 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDTHB' symbol at index 122 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRMB' symbol at index 123 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURILS' symbol at index 126 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCNH' symbol at index 137 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDBRL' symbol at index 139 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   */
  }
```
See also
[StringSubstr](/en/docs/strings/stringsubstr), [StringGetCharacter](/en/docs/strings/stringgetcharacter), [StringLen](/en/docs/strings/stringlen), [StringLen](/en/docs/strings/stringlen)
@@ -0,0 +1,64 @@
# StringGetCharacter
Returns value of a symbol, located in the specified position of a string.
```
ushort  StringGetCharacter(
   string  string_value,     // string
   int     pos               // symbol position in the string
   );
```
Parameters
string_value
[in]  String.
pos
[in]  Position of a symbol in the string. Can be from 0 to [StringLen](/en/docs/strings/stringlen)(text) -1.
Return Value
Symbol code or 0 in case of an error. To get the [error code](/en/docs/constants/errorswarnings/errorcodes) call [GetLastError()](/en/docs/check/getlasterror).
Example:
```
void OnStart()
  {
//--- delete all comments on the chart
   Comment("");
//--- declare a string, from which we will obtain the values of symbol codes and remember the string length
   string message = "The script demonstrates the operation of the StringGetCharacter() function";
   int    length  = StringLen(message);
//--- declare a string variable, to which we will add the obtained symbols from the demo string
   string text    = "";
//--- in the loop by the demo string length
   for(int i=0; i<length; i++)
     {
      //--- wait 1/10 seconds
      Sleep(100);
      //--- get a symbol from a string located at the loop index in the demo string
      ushort char_code=StringGetCharacter(message, i);
      //--- add a symbol to the displayed string and display the resulting string as a chart comment
      text+=ShortToString(char_code);
      Comment(text);
     }
//--- wait two seconds and remove the comment from the chart
   Sleep(2000);
   Comment("");
   
   /*
   Result: the demo string appears on the screen character by character
   The script demonstrates the operation of the StringGetCharacter() function
   */
  }
```
See also
[StringSetCharacter](/en/docs/strings/stringsetcharacter),[ StringBufferLen](/en/docs/strings/stringbufferlen), [StringLen](/en/docs/strings/stringlen), [StringFill](/en/docs/strings/stringfill), [StringInit](/en/docs/strings/stringinit), [StringToCharArray](/en/docs/convert/stringtochararray), [StringToShortArray](/en/docs/convert/stringtoshortarray)
@@ -0,0 +1,55 @@
# StringInit
Initializes a string by specified symbols and provides the specified string size.
```
bool  StringInit(
   string&   string_var,       // string to initialize
   int       new_len=0,        // required string length after initialization
   ushort    character=0       // symbol, by which the string will be filled
   );
```
Parameters
string_var
[in][out]  String that should be initialized and deinitialized.
new_len=0
[in]  String length after initialization. If length=0, it deinitializes the string, i.e. the string buffer is cleared and the buffer address is zeroed.
character=0
[in]  Symbol to fill the string.
Return Value
In case of success returns true, otherwise - false. To get the [error code](/en/docs/constants/errorswarnings/errorcodes) call [GetLastError()](/en/docs/check/getlasterror).
Note
If  character=0 and the length new_len>0, the buffer of the string of indicated length will be distributed and filled by zeroes. The string length will be equal to zero, because the whole buffer is filled out by string terminators.
Example:
```
void OnStart()
  {
//---
   string str;
   StringInit(str,200,0);
   Print("str = ",str,": StringBufferLen(str) = ",
         StringBufferLen(str),"  StringLen(str) = ",StringLen(str));
  }
/*  Result
str = : StringBufferLen(str) = 200   StringLen(str) = 0
*/
```
See also
[StringBufferLen](/en/docs/strings/stringbufferlen), [StringLen](/en/docs/strings/stringlen)
@@ -0,0 +1,44 @@
# StringLen
Returns the number of symbols in a string.
```
int  StringLen(
   string  string_value      // string
   );
```
Parameters
string_value
[in]  String to calculate length.
Return Value
Number of symbols in a string without the ending zero.
Example:
```
void OnStart()
  {
//--- define the test string
   string text="123456789012345";
//--- get the number of symbols in the string
   int str_len=StringLen(text);
//--- display the string and the number of symbols in it in the log
   PrintFormat("The StringLen() function returned the value of %d chars in string: '%s'", str_len, text);
   
   /*
   Result
   The StringLen() function returned the value of 15 chars in string: '123456789012345'
   */
  }
```
See also
[StringBufferLen](/en/docs/strings/stringbufferlen), [StringTrimLeft](/en/docs/strings/stringtrimleft), [StringTrimRight](/en/docs/strings/stringtrimright), [StringToCharArray](/en/docs/convert/stringtochararray), [StringToShortArray](/en/docs/convert/stringtoshortarray)
@@ -0,0 +1,59 @@
# StringSetLength
Sets a specified length (in characters) for a string.
```
bool  StringSetLength(
   string&    string_var,      // string
   uint       new_length       // new string length
   );
```
Parameters
string_var
[in][out]  String, for which a new length in characters should be set.
new_capacity
[in]  Required string length in characters. If new_length is less than the current size, the excessive characters are discarded.
Return Value
In case of successful execution, returns true, otherwise - false. To receive an [error](/en/docs/constants/errorswarnings/errorcodes) code, the [GetLastError()](/en/docs/check/getlasterror) function should be called.
Note
TheStringSetLength() function does not change the size of the buffer allocated for a string.
Example:
```
void OnStart()
  {
//--- define the string
   string text="123456789012345";
   
//--- display a string and its length in the log
   PrintFormat("Before StringSetLength() the string '%s' has a size of %d characters", text, StringLen(text));
   
//--- reduce the string size to 10 characters
   StringSetLength(text, 10);
   
//--- display a string, changed due to StringSetLength() operation, and its new length to the log
   PrintFormat("After StringSetLength() the string is now '%s', and has a size of %d characters", text, StringLen(text));
   
   /*
   Result
   Before StringSetLength() the string '123456789012345' has a size of 15 characters
   After StringSetLength() the string is now '1234567890', and has a size of 10 characters
   */
  }
```
See also
[StringLen](/en/docs/strings/stringlen), [StringBufferLen](/en/docs/strings/stringbufferlen), [StringReserve](/en/docs/strings/stringreserve) [StringInit](/en/docs/strings/stringinit), [StringSetCharacter](/en/docs/strings/stringsetcharacter)
@@ -0,0 +1,55 @@
# StringReplace
It replaces all the found substrings of a string by a set sequence of symbols.
```
int  StringReplace(
   string&         str,              // the string in which substrings will be replaced
   const string    find,             // the searched substring
   const string    replacement       // the substring that will be inserted to the found positions
   );
```
Parameters
str
[in][out]  The string in which you are going to replace substrings.
find
[in]  The desired substring to replace.
replacement
[in]  The string that will be inserted instead of the found one.
Return Value
The function returns the number of replacements in case of success, otherwise -1. To get an [error](/en/docs/constants/errorswarnings/errorcodes) code call the [GetLastError()](/en/docs/check/getlasterror) function.
Note
If the function has run successfully but no replacements have been made (the substring to replace was not found), it returns 0.
The error can result from incorrect str or find parameters (empty or non-initialized string, see [StringInit()](/en/docs/strings/stringinit) ). Besides, the error occurs if there is not enough memory to complete the replacement.
Example:
```
  string text="The quick brown fox jumped over the lazy dog.";
  int replaced=StringReplace(text,"quick","slow");
  replaced+=StringReplace(text,"brown","black");
  replaced+=StringReplace(text,"fox","bear");
  Print("Replaced: ", replaced,". Result=",text);
  
//  Result
//  Replaced: 3. Result=The slow black bear jumped over the lazy dog.
//
```
See also
[StringSetCharacter()](/en/docs/strings/stringsetcharacter), [StringSubstr()](/en/docs/strings/stringsubstr)
@@ -0,0 +1,64 @@
# StringReserve
Reserves the buffer of a specified size for a string in memory.
```
bool  StringReserve(
   string&    string_var,       // string
   uint       new_capacity      // buffer size for storing a string
   );
```
Parameters
string_var
[in][out]  String the buffer size should change the size for.
new_capacity
[in]  Buffer size required for a string. If the new_capacity size is less than the string length, the size of the current buffer does not change.
Return Value
In case of successful execution, returns true, otherwise - false. To receive an [error](/en/docs/constants/errorswarnings/errorcodes) code, the [GetLastError()](/en/docs/check/getlasterror) function should be called.
Note
Generally, the string size is not equal to the size of the buffer meant for storing the string. When creating a string, the appropriate buffer is usually allocated with a margin. The StringReserve() function allows managing the buffer size and specify the optimal size for future operations.
Unlike [StringInit()](/en/docs/strings/stringinit), the StringReserve() function does not change the string contents and does not fill it with characters.
Example:
```
void OnStart()
  {
   string s;
//--- check the operation speed without using StringReserve
   ulong t0=GetMicrosecondCount();
   for(int i=0; i< 1024; i++)
      s+=" "+(string)i;
   ulong msc_no_reserve=GetMicrosecondCount()-t0;
   s=NULL;
//--- now, let's do the same using StringReserve
   StringReserve(s,1024 * 3);
   t0=GetMicrosecondCount();
   for(int i=0; i< 1024; i++)
      s+=" "+(string)i;
   ulong msc_reserve=GetMicrosecondCount()-t0;
//--- check the time
   Print("Test with StringReserve passed for "+(string)msc_reserve+" msc");   
   Print("Test without StringReserve passed for "+(string)msc_no_reserve+" msc");         
/* Result
     Test with StringReserve passed for 50 msc
     Test without StringReserve passed for 121 msc
*/
  }
```
See also
[StringBufferLen](/en/docs/strings/stringbufferlen), [StringSetLength](/en/docs/strings/stringsetlength), [StringInit](/en/docs/strings/stringinit), [StringSetCharacter](/en/docs/strings/stringsetcharacter)
@@ -0,0 +1,66 @@
# StringSetCharacter
Returns copy of a string with a changed character in a specified position.
```
bool  StringSetCharacter(
   string&   string_var,       // string
   int       pos,              // position
   ushort    character         // character
   );
```
Parameters
string_var
[in][out]  String.
pos
[in]  Position of a character in a string. Can be from 0 to [StringLen](/en/docs/strings/stringlen)(text).
character
[in]  Symbol code Unicode.
Return Value
In case of success returns true, otherwise false. In order to get an [error code](/en/docs/constants/errorswarnings/errorcodes), the [GetLastError()](/en/docs/check/getlasterror) function should be called.
Note
If pos is less than [string length](/en/docs/strings/stringlen) and the symbol code value = 0, the string is cut off (but the [buffer size](/en/docs/strings/stringbufferlen), distributed for the string remains unchanged). The string length becomes equal to pos.
If pos is equal to string length, the specified symbol is added at the string end, and the length is enlarged by one.
Example:
```
void OnStart()
  {
   string str="0123456789";
   Print("before: str = ",str,",StringBufferLen(str) = ",
         StringBufferLen(str),"  StringLen(str) = ",StringLen(str));
//--- add zero value in the middle
   StringSetCharacter(str,6,0);
   Print("after: str = ",str,",StringBufferLen(str) = ",
         StringBufferLen(str),"  StringLen(str) = ",StringLen(str));
//--- add symbol at the end
   int size=StringLen(str);
   StringSetCharacter(str,size,'+');
   Print("addition: str = ",str,",StringBufferLen(str) = ",
         StringBufferLen(str),"  StringLen(str) = ",StringLen(str));
  }
/* Result
   before: str = 0123456789 ,StringBufferLen(str) = 0   StringLen(str) = 10
   after:  str = 012345 ,StringBufferLen(str) = 16   StringLen(str) = 6
   addition: str = 012345+ ,StringBufferLen(str) = 16   StringLen(str) = 7
*/
```
See also
[StringBufferLen](/en/docs/strings/stringbufferlen), [StringLen](/en/docs/strings/stringlen), [StringFill](/en/docs/strings/stringfill), [StringInit](/en/docs/strings/stringinit), [CharToString](/en/docs/convert/chartostring), [ShortToString](/en/docs/convert/shorttostring), [CharArrayToString](/en/docs/convert/chararraytostring), [ShortArrayToString](/en/docs/convert/shortarraytostring)
@@ -0,0 +1,60 @@
# StringSplit
Gets substrings by a specified separator from the specified string, returns the number of substrings obtained.
```
int  StringSplit(
   const string   string_value,       // A string to search in
   const ushort   separator,          // A separator using which substrings will be searched
   string         & result[]          // An array passed by reference to get the found substrings
   );
```
Parameters
string_value
[in]  The string from which you need to get substrings. The string will not change.
pos
[in]  The code of the separator character. To get the code, you can use the [StringGetCharacter()](/en/docs/strings/stringgetcharacter) function.
result[]
[out]  An array of strings where the obtained substrings are located.
Return Value
The number of substrings in the result[] array. If the separator is not found in the passed string, only one source string will be placed in the array.
If string_value is empty or NULL, the function will return zero. In case of an error the function returns -1. To get the [error](/en/docs/constants/errorswarnings/errorcodes) code, call the [GetLastError()](/en/docs/check/getlasterror) function.
Example:
```
string to_split="_life_is_good_"; // A string to split into substrings
   string sep="_";                // A separator as a character
   ushort u_sep;                  // The code of the separator character
   string result[];               // An array to get strings
   //--- Get the separator code
   u_sep=StringGetCharacter(sep,0);
   //--- Split the string to substrings
   int k=StringSplit(to_split,u_sep,result);
   //--- Show a comment 
   PrintFormat("Strings obtained: %d. Used separator '%s' with the code %d",k,sep,u_sep);
   //--- Now output all obtained strings
   if(k>0)
     {
      for(int i=0;i<k;i++)
        {
         PrintFormat("result[%d]=\"%s\"",i,result[i]);
        }
     }
```
See also
[StringReplace()](/en/docs/strings/stringreplace), [StringSubstr()](/en/docs/strings/stringsubstr), [StringConcatenate()](/en/docs/strings/stringconcatenate)
@@ -0,0 +1,57 @@
# StringSubstr
Extracts a substring from a text string starting from the specified position.
```
string  StringSubstr(
   string  string_value,     // string
   int     start_pos,        // position to start with
   int     length=-1         // length of extracted string
   );
```
Parameters
string_value
[in]  String to extract a substring from.
start_pos
[in]  Initial position of a substring. Can be from 0 to [StringLen](/en/docs/strings/stringlen)(text) -1.
length=-1
[in] Length of an extracted substring. If the parameter value is equal to -1 or parameter isn't set, the substring will be extracted from the indicated position till the string end.
Return Value
Copy of a extracted substring, if possible. Otherwise returns an empty string.
Example:
```
void OnStart()
  {
//--- get the name of the current symbol
   string name = Symbol();
   
//--- get the base and quoted symbol currencies
   string base   = StringSubstr(name, 0, 3);
   string quoted = StringSubstr(name, 3, 3);
   
//--- display the obtained symbol currencies in the log
   PrintFormat("Symbol: %s. Currency base: %s, currency quoted: %s", name, base, quoted);
  
   /*
   Result
   Symbol: EURUSD. Currency base: EUR, currency quoted: USD
   */
  }
```
See also
[StringSplit](/en/docs/strings/stringsplit), [StringFind](/en/docs/strings/stringfind), [StringGetCharacter](/en/docs/strings/stringgetcharacter)
@@ -0,0 +1,48 @@
# StringToLower
Transforms all symbols of a selected string into lowercase.
```
bool  StringToLower(
   string&  string_var      // string to process
   );
```
Parameters
string_var
[in][out]  String.
Return Value
In case of success returns true, otherwise - false. To get the [error code](/en/docs/constants/errorswarnings/errorcodes) call [GetLastError()](/en/docs/check/getlasterror).
Example:
```
void OnStart()
  {
//--- define the source string in uppercase
   string text=" - THIS STRING, WRITTEN IN UPPERCASE, MUST BE WRITTEN IN LOWERCASE";
//--- Display the source string in the log
   Print("Source line:\n", text);
//--- convert all string characters to lowercase and display the result in the log
   if(StringToLower(text))
      Print("The original string after using the StringToLower() function:\n", text);
      
   /*
   Result
   Source line:
    - THIS STRING, WRITTEN IN UPPERCASE, MUST BE WRITTEN IN LOWERCASE
   The original string after using the StringToLower() function:
    - this string, written in uppercase, must be written in lowercase
   */
  }
```
See also
[StringToUpper](/en/docs/strings/stringtoupper), [StringTrimLeft](/en/docs/strings/stringtrimleft), [StringTrimRight](/en/docs/strings/stringtrimright)
@@ -0,0 +1,48 @@
# StringToUpper
Transforms all symbols of a selected string into capitals.
```
bool  StringToUpper(
   string&  string_var      // string to process
   );
```
Parameters
string_var
[in][out]  String.
Return Value
In case of success returns true, otherwise - false. To get the [error code](/en/docs/constants/errorswarnings/errorcodes) call [GetLastError()](/en/docs/check/getlasterror).
Example:
```
void OnStart()
  {
//--- define the source string in lowercase
   string text=" - this string, written in lowercase, must be written in uppercase";
//--- Display the source string in the log
   Print("Source line:\n", text);
//--- convert all string characters to uppercase and display the result in the log
   if(StringToUpper(text))
      Print("The original string after using the StringToUpper() function:\n", text);
      
   /*
   Result
   Source line:
    - this string, written in lowercase, must be written in uppercase
   The original string after using the StringToUpper() function:
    - THIS STRING, WRITTEN IN LOWERCASE, MUST BE WRITTEN IN UPPERCASE
   */
  }
```
See also
[StringToLower](/en/docs/strings/stringtolower), [StringTrimLeft](/en/docs/strings/stringtrimleft), [StringTrimRight](/en/docs/strings/stringtrimright)
@@ -0,0 +1,48 @@
# StringTrimLeft
The function cuts line feed characters, spaces and tabs in the left part of the string till the first meaningful symbol. The string is modified at place.
```
int  StringTrimLeft(
   string&  string_var      // string to cut
   );
```
Parameters
string_var
[in][out]  String that will be cut from the left.
Return Value
Returns the number of cut symbols.
Example:
```
void OnStart()
  {
//--- define the source string with six spaces on the left
   string text="      All spaces on the left will be removed from this string";
//--- Display the source string in the log
   PrintFormat("Source line:\n'%s'", text);
//--- remove all spaces on the left and display the number of removed characters and the resulting string in the log
   int num=StringTrimLeft(text);
   PrintFormat("The StringTrimLeft() function removed %d chars from the left side. Now the line looks like this:\n'%s'", num, text);
   
   /*
   Result
   Source line:
   '      All spaces on the left will be removed from this string'
   The StringTrimLeft() function removed 6 chars from the left side. Now the line looks like this:
   'All spaces on the left will be removed from this string'
   */
  }
```
See also
[StringTrimRight](/en/docs/strings/stringtrimright), [StringToLower](/en/docs/strings/stringtolower), [StringToUpper](/en/docs/strings/stringtoupper)
@@ -0,0 +1,48 @@
# StringTrimRight
The function cuts line feed characters, spaces and tabs in the right part of the string after the last meaningful symbol. The string is modified at place.
```
int  StringTrimRight(
   string&  string_var      // string to cut
   );
```
Parameters
string_var
[in][out]  String that will be cut from the right.
Return Value
Returns the number of cut symbols.
Example:
```
void OnStart()
  {
//--- define the source string with six spaces on the right
   string text="All spaces on the right will be removed from this string      ";
//--- Display the source string in the log
   PrintFormat("Source line:\n'%s'", text);
//--- remove all spaces on the right and display the number of removed characters and the resulting string in the log
   int num=StringTrimRight(text);
   PrintFormat("The StringTrimRight() function removed %d chars from the right side. Now the line looks like this:\n'%s'", num, text);
   
   /*
   Result
   Source line:
   'All spaces on the right will be removed from this string      '
   The StringTrimRight() function removed 6 chars from the right side. Now the line looks like this:
   'All spaces on the right will be removed from this string'
   */
  }
```
See also
[StringTrimLeft](/en/docs/strings/stringtrimleft), [StringToLower](/en/docs/strings/stringtolower), [StringToUpper](/en/docs/strings/stringtoupper)