Split Function In The String

This is to introduce the function, the Split function, where we can split the strings with a single character which can be a white space (' '), comma operator (','), or any other words. 
 
We require the two things to split the string obviously first one the string which we want to split and the second one is the array that stores the array which we have split.
  1. string str="Hello, Hi Good Morning!";  
  2. string[] strarr=str.split(' ');  //split with the white space..  
  3. string[] strarr1=str.split(','); //split with the comma operator..  
The following is the foreach with which we can use to print the string array to show the string or the words or the variables.
  1. foreach(string str1 in strarr)  
  2. {  
  3.    Console.WriteLine(str1);  
  4. }  
  5. //Output  
  6. //Hello,  
  7. //Hi  
  8. //Good  
  9. //Morning!  
The following is the full source code 
  1. using System;  
  2. class Demo1  
  3. {  
  4.     static void Main()   
  5.     {  
  6.         string str="Hello, Hi Good Morning!";    
  7.         string[] strarr=str.Split(' ');  //split with the white space..    
  8.         string[] strarr1=str.Split(','); //split with the comma operator..    
  9.         //First String Array..  
  10.         Console.WriteLine("Frist String Array..");  
  11.         foreach(string str1 in strarr)  
  12.         {  
  13.             Console.WriteLine(str1);  
  14.         }  
  15.         Console.WriteLine("\n"+"Second String Array"+"\n");  
  16.         //Second String Array..  
  17.         foreach(string str1 in strarr1)  
  18.         {  
  19.             Console.WriteLine(str1);  
  20.         }  
  21.     }  
  22. }  
  23. //Output  
  24. //First String Array..  
  25. //Hello,  
  26. //Hi  
  27. //Good  
  28. //Morning!  
  29. //  
  30. //Second String Array  
  31. //Hello  
  32. //   Hi Good Morning!