The StringBuilder object is the more advanced version of the string variable that is designed to work better with very large strings. It is in the System.Text namespace so it is not easily available by default.
It is an auxiliary object used for manipulating characters. It contains a buffer, typically initialized with a string but usually larger than that string. This buffer can be manipulated in place without creating a new string: You can insert, append, remove, and replace characters. When you're done manipulating the characters, use StringBuilder's ToString method to extract the finished string from it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringBuilderClass
{
class Program
{
static void Main(string[] args)
{
String TestStringBuilder;
StringBuilder OtherStringBuilder = new StringBuilder("Hello");
OtherStringBuilder.Remove(2, 3); // produces "He"
OtherStringBuilder.Insert(2, "lp"); // produces "Help"
OtherStringBuilder.Replace('l', 'a'); // produces "Heap"
TestStringBuilder = OtherStringBuilder.ToString();
}
}
}
No comments:
Post a Comment