myeatrade

MQL4 Reference

MQL4 String functions

A group of functions intended for working with data of the string type.

 

StringConcatenate()

string StringConcatenate(...)

Forms a string of the data passed and returns it. Parameters can be of any type. Amount of passed parameters cannot exceed 64.

Parameters are transformed into strings according the same rules as those used in functions of Print(), Alert() and Comment(). The returned string is obtained as a result of concatenate of strings converted from the function parameters.

The StringConcatenate() works faster and more memory-saving than when strings are concatenated using addition operations (+).

Parameters:

... - Any values separated by commas. It can be up to 64 parameters. 

Sample:

  string text;
  text=StringConcatenate("Account free margin is ", AccountFreeMargin(), "Current time is ", TimeToStr(TimeCurrent()));
// slow text="Account free margin is " + AccountFreeMargin() + "Current time is " + TimeToStr(TimeCurrent())
  Print(text);

StringFind()

int StringFind(string text, string matched_text, int start=0)

Search for a substring. Returns the position in the string from which the searched substring begins, or -1 if the substring has not been found.

Parameters:

text         - String to search in. 
matched_text - Substring to search for. 
start        - Position in the string to start search from. 

Sample:

  string text="The quick brown dog jumps over the lazy fox";
  int index=StringFind(text, "dog jumps over", 0);
  if(index!=16)
    Print("oops!");

StringGetChar()

int StringGetChar(string text, int pos)

Returns character (code) from the specified position in the string.

Parameters:

text - String. 
pos  - Char position in the string. Can be from 0 to StringLen(text)-1.  

Sample:

  int char_code=StringGetChar("abcdefgh", 3);
  // char code 'c' is 99

StringLen()

int StringLen(string text)

Returns character count in a string.

Parameters:

text - String where the length must be calculated.   

Sample:

  string str="some text";
  if(StringLen(str)<5) return(0);

StringSetChar()

string StringSetChar(string text, int pos, int value)

Returns the string copy with changed character in the specified position.

Parameters:

text  - String where character will be changed. 
pos   - The character position in the string. Can be from 0 to StringLen(text). 
value - New char ASCII code. 

Sample:

  string str="abcdefgh";
  string str1=StringSetChar(str, 3, 'D');
  // str1 is "abcDefgh"

StringSubstr()

string StringSubstr(string text, int start, int length=0)

Extracts a substring from text string starting from the given position.

The function returns a copy of the extracted substring if possible, otherwise, it returns an empty string.

Parameters:

text   - String from which the substring will be extracted. 
start  - Substring starting index. Can be from 0 to StringLen(text)-1. 
length - Length of the substring extracted. 
         If the parameter value exceeds or equals to 0 or the parameter is not specified, 
         the substring will be extracted starting from the given position and up to the end of the string.. 

Sample:

  string text="The quick brown dog jumps over the lazy fox";
  string substr=StringSubstr(text, 4, 5);
  // subtracted string is the "quick" word

StringTrimLeft()

string StringTrimLeft(string text)

The function cuts line feed characters, spaces and tabs in the left part of the string. The function returns a copy of the trimmed string, if possible. Otherwise, it returns an empty string.

Parameters:

text - String to be trimmed at the left.  

Sample:

  string str1="  Hello world   ";
  string str2=StringTrimLeft(str);
  // after trimming the str2 variable will be "Hello World   "

StringTrimRight()

string StringTrimRight(string text)

The function cuts line feed characters, spaces and tabs in the right part of the string. The function returns a copy of the trimmed string, if possible. Otherwise, it returns an empty string.

Parameters:

text - String to be trimmed at the right.  

Sample:

  string str1="  Hello world   ";
  string str2=StringTrimRight(str);
  // after trimming the str2 variable will be "  Hello World"
This article url: http://www.myeatrade.com/451/

Please login to post comment, if you haven't account you can register free