Inserting, replacing, and removing : String Replace « Data Types « C# / C Sharp






Inserting, replacing, and removing

Inserting, replacing, and removing
   
/*
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); 
  } 
}

           
         
    
    
  








Related examples in the same category

1.Replace char inside a string
2.use the Insert(), Remove(), and Replace() methods to modify strings
3.String reverse and replaceString reverse and replace
4.String insert and outputString insert and output
5.remove any of a set of chars from a given string.
6.Replaces the specified string to replace.
7.Replace Once
8.Replaces the new lines in a string with the given replacement characters.