A StringBuilder object is not a string StringBuilder object used for manipulating characters.  StringBuilder object is mutable it means once we create string builder object we can perform any operation like insert, append, remove, and replace without creating new instance for every time.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // insert string using String Builder
            String MyName;
            StringBuilder Name = new StringBuilder("Aditya");           
            Name.Insert(6, "Kumar");           
            MyName = Name.ToString();
            Console.WriteLine("Your Name: " + MyName);
 
            // append string using String Builder
            StringBuilder sb = new StringBuilder("");
            sb.Append("rajeev");
            sb.Append("kumar");
          string strFullName = sb.ToString();
         Console.WriteLine("Your Name: " +strFullName);
 
         Console.ReadLine();
        }
    }
}

 

Output:



STRINGBUILDER

StringBuilder we can use insert, append, remove, and replace  keyword.

Stringbuilder  belongs to System.Text namespace


Thanks.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like