Demonstrating method Replace. - CSharp Language Basics

CSharp examples for Language Basics:StringBuilder

Description

Demonstrating method Replace.

Demo Code



using System;//from   w w w.j  a va 2  s  .c o  m
using System.Text;

class StringBuilderReplace
{
   static void Main()
   {
      var builder1 = new StringBuilder("Happy Birthday Jane");
      var builder2 = new StringBuilder("goodbye greg");

      Console.WriteLine($"Before replacements:\n{builder1}\n{builder2}");

      builder1.Replace("Jane", "Greg");
      builder2.Replace('g', 'G', 0, 5);

      Console.WriteLine($"\nAfter replacements:\n{builder1}\n{builder2}");
   }
}

Result


Related Tutorials