Split number

 

I want code to split number and text, every number and text after "," will be add to variable.


example : 454,343,55464,2342,85675,asad


Anyone can help me make the codes plz

 
akram:

I want code to split number and text, every number and text after "," will be add to variable.


example : 454,343,55464,2342,85675,asad


Anyone can help me make the codes plz



int getTokens(string sss, string &tokens[])
{
int start_at=0;
int nValues=0;

int idx=0;

while(idx< StringLen(sss))
{
idx = StringFind(sss,",",start_at);
if(idx!=-1)
{
string val=StringSubstr(sss,start_at,idx-start_at);
tokens[nValues]= val;
nValues++;
start_at=idx+1;
}
else {
//Print(StringLen(sss)+" "+ start_at+" "+(StringLen(sss)-start_at));
val=StringSubstr(sss,start_at,StringLen(sss)-start_at);
tokens[nValues]= val;
nValues++;
break;
}

}
return(nValues);
}



int start()
{

string sss="454,343,55464,2342,85675,asad";
string values[100];

int nValues=getTokens(sss, values);

Print("-------");
for(int i = 0; i< nValues; i++)
Print("values["+i+"]="+"'"+values[i]+"'");

}



16:30:11 body_trader_6 EURUSDm,M1: values[0]='454'
16:30:11 body_trader_6 EURUSDm,M1: values[1]='343'
16:30:11 body_trader_6 EURUSDm,M1: values[2]='55464'
16:30:11 body_trader_6 EURUSDm,M1: values[3]='2342'
16:30:11 body_trader_6 EURUSDm,M1: values[4]='85675'
16:30:11 body_trader_6 EURUSDm,M1: values[5]='asad'

 

Thank for help :) god bless u

 

Akram/Others -

MQL4 is very, very similar to C. For common data manipulation functions look here, and at C websites for code samples.