How to separete input="a,b,c"

 
input string ="a,b,c,d";

I want to know how to separate by comma, strings and print them.

For example,

I want to make output using Print like,,,,


My name is a.

I like b.

Do you know c?

I hate c.

 
kajironpu:

I want to know how to separate by comma, strings and print them.

Use StringSplit() to place them in an array and then access the array for your prints.

 
Keith Watford:

Use StringSplit() to place them in an array and then access the array for your prints.

Thanks! I will try.
 
kajironpu:

I want to know how to separate by comma, strings and print them.

For example,

I want to make output using Print like,,,,


My name is a.

I like b.

Do you know c?

I hate c.

//+------------------------------------------------------------------+
//|                                                        Split.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
input string to_split="a,b,c,d";
   string sep=",";                // A separator as a character 
   ushort u_sep;                  // The code of the separator character 
   string result[];               // An array to get strings 
   //--- Get the separator code 


void OnStart()
  {
//---
   u_sep=StringGetCharacter(sep,0); 
   //--- Split the string to substrings 
   int k=StringSplit(to_split,u_sep,result); 
   
   if(k>0) 
     { 
      for(int i=0;i<k;i++) 
        { 
         Print("i: ",i," = ",result[i]); 
        } 
     }

  }
//+------------------------------------------------------------------+
 

kajironpu:

Do you know c?

I hate c.

c isn't so bad once you get to know him.

 
Anthony Garot:

c isn't so bad once you get to know him.

:))

 
Mehmet Bastem:

You can shorten your code:

#property strict   
   input string to_split="a,b,c,d";
   ushort u_sep=',';              // The code of the separator character 
   string result[];               // An array to get strings 

void OnStart()
  {
   //--- Split the string to substrings
   int k=StringSplit(to_split,u_sep,result);
   for(int i=0;i<k;i++)
      Print("i: ",i," = ",result[i]);
  }
Reason: