Split and join strings : String Split : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » String Split »

 

Split and join strings









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Split and join strings. 
 
using System; 
 
public class SplitAndJoinDemo { 
  public static void Main() { 
    string str = "One if by land, two if by sea."; 
    char[] seps = {' ', '.', ',' }; 
 
    // Split the string into parts. 
    string[] parts = str.Split(seps); 
    Console.WriteLine("Pieces from split: "); 
    for(int i=0; i < parts.Length; i++) 
      Console.WriteLine(parts[i]); 
    
    // Now, join the parts. 
    string whole = String.Join(" | ", parts); 
    Console.WriteLine("Result of join: "); 
    Console.WriteLine(whole); 
  } 
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» String Split