Download MetaTrader 5

what is the difference of "\t" and '\t' ? - page 2

To add comments, please log in or register
ydrol
593
ydrol 2014.03.20 23:07  
gooly:

Well to me it's still funny.

I join a string by:

but I can't split this string using "\t" with which I glue the items together?



I understand what you are saying. You would like string split to have been implemented as StringSplit(string,string,string &[]) rather than a single char for splitting. There may be some merit in that point of view. (more versatile and yet 'simpler' for non-coders), But MQL have not implemented it that way.

If you really want to make you own StringSplit(string,string,string &[]) that makes you happy, you could probably combine StringReplace and StringSplit but it will need to be careful!

qjol
3243
qjol 2014.03.20 23:24  

or you can build your own function

https://www.mql5.com/en/forum/116685

ydrol
593
ydrol 2014.03.21 00:38  
qjol:

or you can build your own function

https://www.mql5.com/en/forum/116685


Now we have StringReplace and StringSplit it would be much simpler, and faster to use

// not real code - error handling and selection of USHORT separator ommitted to etc. 

int MyStringSplit(string in,string sep,string &out[]) {

    StringReplace(in,sep, string form of SOME_USHORT_NOT_IN_STRING);

    return StringSplit(in, SOME_USHORT_NOT_IN_STRING,out);

}
qjol
3243
qjol 2014.03.21 03:48  

I wrote, "or you can build your own function" It's up to him

personally i prefer not to change the source string, and leave it as is (by using StringReplace you are changing the source), just to use a copy (string& Out[])

but again, each one with is personal preference

ydrol
593
ydrol 2014.03.21 09:38  

qjol I wrote, "or you can build your own function"

I didnt quite get the 'or' because I was also suggesting the same thing -

[me]If you really want to make you own StringSplit ...

[you]or build your own function'

[me]huh??

It would have made more sense to me if your post read 'or you can do it like this'.

qjol: personally i prefer not to change the source string, and leave it as is

It would not change the source because 'in' is is pass by value in

int MyStringSplit(string in,string sep,string &out[]) 

For clarity you could simply assign 'in' to another string 'inCopy'.

I'd rather a two line function calling built- in functions than the alternative implementation which will be slower and potentially makes many calls to ArrayResize (although there are ways around that, esp with the new ArrayResize), but like you say, personal preference :)

Also I've ommited the check to ensure that USHORT is not already in the original string. So maybe it will end up about 6 lines


Also the last parameter in StringSubstr is changed in MQL4++ so the linked function will need modifying. But that's quite simple once one is aware of it.

12
To add comments, please log in or register