2
Answers

NP132 StringBuilder/Remove()

Maha

Maha

16y
4.1k
1

Hi Guys

 

NP132 StringBuilder/Remove()

 

In the following what is the function of Remove() method (highlighted in yellow). Because I am unable to understand the following second output. Please explain.

 

myStringBuilder = frRoomans, Romans, friends, iends

 

Thank you

 

using System;

using System.Text;

 

class MainClass

{

    public static void Main()

    {

        StringBuilder myStringBuilder = new StringBuilder();

 

        myStringBuilder.Append("friends");

 

        myStringBuilder.Insert(2, "friends, ");

        myStringBuilder.Insert(2, "Romans, ", 3);

 

        Console.WriteLine("myStringBuilder = " + myStringBuilder);

 

        myStringBuilder.Remove(4, 7);

        Console.WriteLine("myStringBuilder = " + myStringBuilder);

 

    }

}

/*

myStringBuilder = frRomans, Romans, Romans, friends, iends

myStringBuilder = frRoomans, Romans, friends, iends

*/


Answers (2)