Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Replacing a substring in a String Builder object in C#

Using replace(), you can replace a string with a new string.

  1. using System;
  2. using System.Text;
  3.  
  4. namespace forgetCode
  5. {
  6. class program
  7. {
  8. public static void Main()
  9. {
  10.  
  11. StringBuilder sb1 = new StringBuilder("Time is gold");
  12. sb1.Replace("is", "was");
  13. Console.WriteLine(sb1);
  14. }
  15. }
  16. }


Output:
Time was gold