StringSplit AUDUSD

 

This code failed to return the number 6 which is how many char in a forex symbol, any idea how to fix it?

Thanks

  string symbolArr[];
  int k = StringSplit(Symbol(), "", symbolArr);
  Print("k is: " + k); // prints "1" but "6" is expected.
 
samjesse:

This code failed to return the number 6 which is how many char in a forex symbol, any idea how to fix it?

Thanks

Try to read the documentation of StringSplit() maybe ?
 
Alain Verleyen:
Try to read the documentation of StringSplit() maybe ?

I read it 2 times but could not figure out what would the delimiter be for a char boundary? too bad mql4 does not use regex.

 StringSplit(Symbol(), StringGetCharacter("", 0), symbolArr);
Did not do it either.
 
samjesse:

I read it 2 times but could not figure out what would the delimiter be for a char boundary? too bad mql4 does not use regex.

The second parameter need to be a ushort, something like ','

You can't use an empty string, split nothing, so result is 1.

If you want the number of character use StringLen().

 
use StringLen and StringSubstr
 
samjesse:

This code failed to return the number 6 which is how many char in a forex symbol, any idea how to fix it?

Thanks


You used sting split wrongly . In order to use the string split function correctly you have to enter the separation symbol using ushort  symbol of the character . For example if the separation is _ then then you use 
Charachtergetshort(char'index)
Then you use the resulted value into the string split function

However in this case you mentioned there is no separation between the base and related currency AudUSD so using string split is not the correct way
It's better to consider StringSubString() function
 
Taras Slobodyanik #:
use StringLen and StringSubstr

Thank you.

I had similar issue, I used this to StringLen and StringGetChar, and CharToStr to split "Opinion" into separate character. It solved my issue.

 
String Manipulation Functions
String Manipulation Functions
  • www.mql5.com
A collection of useful string manipulation functions.
Reason: