Regular expression with For each and split : Split : Regular Expressions C# Source Code


Custom Search

C# Source Code » Regular Expressions » Split »

 

Regular expression with For each and split









    

/*
Learning C# 
by Jesse Liberty

Publisher: O'Reilly 
ISBN: 0596003765
*/

 using System;
 using System.Text;
 using System.Text.RegularExpressions;

 namespace RegularExpressions
 {
    public class TesterRegularExpressions
    {
       public void Run()
       {
           string s1 =
               "One,Two,Three Liberty Associates, Inc.";
           Regex theRegex = new Regex(" |, |,");
           StringBuilder sBuilder = new StringBuilder();
           int id = 1;

           foreach (string subString in theRegex.Split(s1))
           {
               sBuilder.AppendFormat(
                   "{0}: {1}\n", id++, subString);
           }
           Console.WriteLine("{0}", sBuilder);
       }

       [STAThread]
       static void Main()
       {
          TesterRegularExpressions t = new TesterRegularExpressions();
          t.Run();
       }
    }
 }

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Regular Expressions
» Split