using System.Text;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string input = "Amar,Akbar,Antony are Friends!"; //Input String
// Split Whenever the , and space is encounterd in the input string
string pattern = "( |,)"; //RegEx Patter
Regex regex = new Regex(pattern);
StringBuilder str = new StringBuilder();
//The Split() method returns An array of strings so store it in the array of String Type
string[] substr = regex.Split(input);
int count = 1; //In order to prfix the splitted words with counter from 1 to ....
foreach (string match in substr)
{
//Eliminate the , and space in the splitted array i.e, substr otherwise we get , and space in output
if (match == "," || match == " ")
{
continue;
}
else
{
//Simply format the output by prefixing the Pattern
str.AppendFormat("{0}: {1}", count++, match);
}
}
Console.WriteLine(str);
}
}

