Regex Split Function

Pranat
0
Lamp

 using System.Text.RegularExpressions;

using System.Text;

class PramodRegex

{

 public static void Main()

 {

 //string reg = "( |,)"; //RegEx Patter

 string str = "Amar,Akbar,Antony are Friends!";

 Regex reg = new Regex(" |,");

 StringBuilder sb = new StringBuilder();

 int count = 1;

 foreach(string sub in reg.Split(str))

 {

 sb.AppendFormat("{0}: {1}\n", count++, sub);

 }

 Console.WriteLine(sb);

 }

}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !