In this source code example, we will demonstrate the usage of SpringBuilder.Insert method in C# with an example.
The Insert method is used to insert a string into the specified position of the builder.
C# StringBuilder Insert Example
The example inserts a string into a sentence with the Insert method:
using System;
using System.Text;
class StringBuilderExample {
static void Main() {
var sentence = "SourceCodeExamples is a programming website";
var builder = new StringBuilder(sentence);
builder.Insert(24, "coding and ");
Console.WriteLine(builder);
}
}
Output:
SourceCodeExamples is a coding and programming website