use the Insert(), Remove(), and Replace() methods to modify strings : String Replace « Data Types « C# / C Sharp






use the Insert(), Remove(), and Replace() methods to modify strings

    

using System;

class MainClass {

    public static void Main() {

        string[] myStrings = {"To", "be", "or", "not","to", "be"};
        string myString = String.Join(".", myStrings);    
                
        string myString10 = myString.Insert(6, "friends, ");
        Console.WriteLine("myString.Insert(6,\"friends, \") = " + myString10);
        string myString11 = myString10.Remove(14, 7);
        Console.WriteLine("myString10.Remove(14, 7) = " + myString11);
        string myString12 = myString11.Replace(',', '?');
        Console.WriteLine("myString11.Replace(',', '?') = " + myString12);
        string myString13 =myString12.Replace("to be", "Or not to be friends");
        Console.WriteLine("myString12.Replace(\"to be\",\"Or not to be friends\") = " + myString13);
    
    }
}

   
    
    
  








Related examples in the same category

1.Replace char inside a string
2.String reverse and replaceString reverse and replace
3.Inserting, replacing, and removingInserting, replacing, and removing
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.