I need some string functions like LCase, UCase, Replace(), Instr(), Instrrev(), etc... anyone know how?

 

Seems like there are no string functions in mq4?

I want to load a file that contains my strategy settings. This file gets updated by another program. Basicly, the file is a single line of text, which each value seperated by a TAB (tab dilemted file). I've figured out how to ge my EA to load the file. Now I just want to split the file up by tabs, so I can use each value in my strategy. But, I can't figure out how to do that, without some basic string functions.

I have a nice set of C# functions tha I am used to using, so I tried to copy them into my EA, but they won't compile because they try to use many of the function I mentioned in my subject line for this topic. Anyone know how to access these string manipulation functions in an EA?

Thanks!

I need: LCase, UCase, Replace(), Instr() or Contains(), InstrRev() would be nice too, etc.

 

For reading the contents of TAB delimited files you can directly use the file functions, no need for string manipulation.


Otherwise it should be possible to implement all the above mentioned functions from scratch with what is already available in mql4 and some are already available (searching for substrings, and extracting substrings is already there). Read through the available string functions documentation to see what can be used as a starting point for your needs.


Here is some inspiration (it does not solve your problem, it is only an example for how I implement what is missing):


/**
* search for the string needle in the string haystack and replace all
* occurrecnes with replace.
*/
string stringReplace(string haystack, string needle, string replace=""){
   string left, right;
   int start=0;
   int rlen = StringLen(replace);
   int nlen = StringLen(needle);
   while (start > -1){
      start = StringFind(haystack, needle, start);
      if (start > -1){
         if(start > 0){
            left = StringSubstr(haystack, 0, start);
         }else{
            left="";
         }
         right = StringSubstr(haystack, start + nlen);
         haystack = left + replace + right;
         start = start + rlen;
      }
   }
   return (haystack);  
}


For reading TAB delimited strings or numbers out of a file as you described it it is already enough to use the file functions FileReadString() and FileReadNumber() with a file opened in CSV mode and the TAB character set as the delimiter, this would work without needing any of the string functions at all. It is all described in the manual (press F1 in MetaEditor to see the manual or here on this website click on documentation in the upper left).


Otherwise you only need StringFind() and StringSubstr() in a loop if you want to split a string manually, no need to port immense loads of C# code and all the other functions mentioned for such a simple task.

 

I agree. open a csv with delimiter="\t"

as for LCase, create one:

string Lcase(string s){
   for (int i=StringLen(s)-1; i>=0; i--){
      int C=StringGetChar(s,i);
      if (C>='A' && C<='Z') s=StringSetChar(s,i,C+'a'-'A');
   }
   return(s);
}
Reason: