what is the difference of "\t" and '\t' ?

 

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?

 
because the first code represent a horizontal tab and second represent a string contains the 2 characters "\" and a "t"
 
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.

 
RaptorUK:


. . . I could be wrong though.


no, you don't
 
  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?
 
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);
 
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
 
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?

 

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)

Reason: