NavigationUser loginWho's new
Who's onlineThere are currently 0 users and 40 guests online.
|
String functionsHi folks, Our set of functions today are the String Functions. They are the MQL4 functions we need to handle the string variables!
string data type:The string data type is an array of characters enclosed in double quote ("). See figure 1 for a simple representation of the string constant “hello” in the characters array.
Figure 1 – Characters array MQL4 limits the size of the string variable to 255 characters and any character above 255 characters will generate this error: (too long string (255 characters maximum)). We use the keyword string to create a string variable. For example:
Now let's study the MQL4 functions concerned about the Strings:
StringConcatenate:Syntax:
Description: The StringConcatenate function take the set of parameters passed to it and glue them together and returns them as a string. Note: (...) means that you can pass to this function any kind of data type and any number of parameters separated by comma. You can pass to this function any kind of data type except the arrays and any number of parameters separated by comma very like the Print(), Alert() and Comment() functions. Note: You can use the + operator to add string to another string for example "coders" + "guru" will produce "codersguru", however MetaTrader saying that StringConcatenate() function works faster gluing strings together. Parameters: This function takes any number of parameters: ... Any values, separated by commas. Example:
StringFind:Syntax:
Description: The StringFind function search for substring (part of the given string for example "gur" is substring from the string "codersguru") in a given string, if the function find the substring it returns its position, if the function didn't find the substring it returns -1. Parameters: This function takes two parameters: string text The string you want to search in it for the substring. string matched_text The substring you want to find it in the string. int start=0 The index of the starting position for the search. the first character in the string has the index 0 then 1 then 2 etc. Example:
StringGetChar:Syntax:
Description: The StringGetChar function returns the character in a given position from a given string. it return it as character code (the ASCII code of the character). Parameters: This function takes two parameters: string text The string you want to get the character from. int pos The position of the character you want to get, don't forget that the string array starts with 0. Example:
StringLen:Syntax:
Description: The StringLen function returns how many character (the length) of the given string. Parameters: This function takes only one parameter: string text The string you want to get its length.. Example:
StringSetChar:Syntax:
Description: The StringSetChar function change one character of the given string in a given position to another character and returns the new string. Parameters: This function takes three parameters: string text The string you want change a character in it. int pos The position of the character you want to change. int value The new character you want to set it. Example:
StringSubstr:Syntax:
Description: The StringSubstr function extracts the string from given position to a given count (ex: "codersguru" the position is 3 and the count is 2 then the extracted string is "de"). The function returns the extracted string if any or it returns EMPTY string. Parameters: This function takes three parameters: string text The string you want to extract from it. int start Where to start your extracting. int count=EMPTY The count of character you want to extract. The default value is EMPTY. Example:
|