Download MetaTrader 5
To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
Carl Schreiber
5965
Carl Schreiber 2014.03.20 15:04 

Splitting a string works if I use:

StringSplit(strFile,'\t',arrTab);

but this does not:

StringSplit(strFile,"\t",arrTab);

What is the difference that one works the other not?

qjol
3243
qjol 2014.03.20 15:14  
because the first code represent a horizontal tab and second represent a string contains the 2 characters "\" and a "t"
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.20 15:16  
gooly:

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.

qjol
3243
qjol 2014.03.20 15:33  
RaptorUK:


. . . I could be wrong though.


no, you don't
whroeder1
13653
whroeder1 2014.03.20 15:34  
  1. '\t' is the number 9, the ASCII code for a tab
  2. "\t" is a string containing a tab.
  3. 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?
Carl Schreiber
5965
Carl Schreiber 2014.03.20 17:28  
I still don't understand why'\t' splitts and "\t" doesn't.There should be a type cast which fails if I use StringSpli("...","\t",array);
whroeder1
13653
whroeder1 2014.03.20 17:49  
Do you think this works?
int four = 2 + "2";
The second argument must be an int and "\t" is a string.
Carl Schreiber
5965
Carl Schreiber 2014.03.20 18:05  

hmm - ok:

        Print('2' + "2");
=> 2014.03.20 19:03:30.829      test GBPUSD,M1: 502
ydrol
595
ydrol 2014.03.20 20:00  
gooly:
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?

Carl Schreiber
5965
Carl Schreiber 2014.03.20 22:22  

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?

qjol
3243
qjol 2014.03.20 22:55  

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)

/ /12
To add comments, please log in or register