Download MetaTrader 5
To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
Icham Aidibe
9915
Icham Aidibe 2014.11.26 23:56 

Hi,

I trade on some contract I have to renew each month or each 2 months, the contract prefix is the same, only the suffix changes - here's the template : <Name><Month : Dec/Nov/Mar etc ..><year : 14, 15 etc ...>

if ((StringFind(_Symbol,1,0) != -1) || (StringFind(_Symbol,2,0) != -1)) { <- Search for a 1 or a 2 inside the symbol name - works 'til 2020, could go to 2090   
   int Len = StringLen(_Symbol); <- In my case, it's NGasJan15, so returns 9
   string SymbolSuffix = StringSubstr(_Symbol, Len - 5); <- Suffix always with 5  
   printf("Symbol : %S / Suffix : %S / Len : %g",_Symbol,SymbolSuffix,Len );

Here's what I get, I want to remove the Jan15, but I can only isolate the J from "Jan15" PLUS the Symbol name doesn't show as it is in the market watch :/ (NGasJan15) but the good length ^_^'

2014.11.26 23:06:34	Core 1	2014.05.29 00:00:00   Symbol : N / Suffix : J / Len : 9

I'm wondering why ... in the documentation, there's a third param to this func, here's what it's said about :

length=-1

[in] Length of an extracted substring. If the parameter value is equal to -1 or parameter isn't set, the substring will be extracted from the indicated position till the string end.
Any help ?
Enrico Lambino
4281
Enrico Lambino 2014.11.27 05:53  

Try this one:

printf("Symbol : %s / Suffix : %s / Len : %g",_Symbol,SymbolSuffix,Len );
Icham Aidibe
9915
Icham Aidibe 2014.11.27 07:44  
Iceron:

Try this one:

Thank you, that way it works ... no %S but %s.
/
To add comments, please log in or register