Inserting, replacing, and removing

image_pdfimage_print

   

/*
C#: The Complete Reference 
by Herbert Schildt 

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


// Inserting, replacing, and removing. 
  
using System;  
  
public class InsRepRevDemo {  
  public static void Main() {  
    string str = "This test"; 
 
    Console.WriteLine("Original string: " + str); 
     
    // Insert 
    str = str.Insert(5, "is a "); 
    Console.WriteLine(str); 
 
    // Replace string 
    str = str.Replace("is", "was"); 
    Console.WriteLine(str); 
 
    // Replace characters 
    str = str.Replace('a', 'X'); 
    Console.WriteLine(str); 
 
    // Remove 
    str = str.Remove(4, 5); 
    Console.WriteLine(str); 
  } 
}

           
          


This entry was posted in Data Types. Bookmark the permalink.