Splitting a string works if I use:
but this does not:
What is the difference that one works the other not?
I think . . .
"\t" is a string
'\t' is a character ASCII 9
. . . I could be wrong though.
. . . I could be wrong though.
no, you don't
- '\t' is the number 9, the ASCII code for a tab
- "\t" is a string containing a tab.
- From the doc
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 );
Why would you expect it to even compile using a string?
Do you think this works? | int four = 2 + "2";The second argument must be an int and "\t" is a string. |
hmm - ok:
Print('2' + "2"); => 2014.03.20 19:03:30.829 test GBPUSD,M1: 502
There should be a type cast
Why should there be? We are but slaves to the rules of MQL.
'+' is a funny operator. It does two completely different things.. but if one aregument is a string, it tries to make the other a string to (I hope!) and then put them side by side, but if both arguments are numbers, it does arithmetic.
In any case '2' + "2" means 50 + "2". So it is converting a ushort to a string. That is complete opposite to want you want MQL to do (implicitly make a 1 character string a ushort ). Why fight it?
Well to me it's still funny.
I join a string by:
"x1\tx2\tx3\tx4" or "x1" + "\t" +"x2+ "\t" + "x3" + "\t" + "x4"
but I can't split this string using "\t" with which I glue the items together?
try
"x1" + "\\t" + "x2" + "\\t" + "x3" + "\\t" + "x4";
If you need to include a double quote (") into a string, the backslash character (\) must be put before it. Any special character constants can be written in a string, if the backslash character (\) is typed before them. (https://docs.mql4.com/basis/types/stringconst)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Splitting a string works if I use:
but this does not:
What is the difference that one works the other not?