How do I insert a text into String?
Category: System, viewed: 915 time(s).
In this example we use the String.Insert() and StringBuilder.Insert() methods to insert a text into a string.
using System;
using System.Text;
namespace Kodecsharp.Example.System
{
public class InsertText
{
public static void Main(string[] args)
{
string text = "The fox jumps over the lazy dog";
//
// Insert a text into string using String.Insert() method. The method
// accept the index where the new text will be inserted.
//
text = text.Insert(4, "quick brown ");
Console.WriteLine(text);
//
// Insert a text into string using StringBuilder.Insert() method.
//
StringBuilder builder = new StringBuilder("Jackdaws love my big quartz");
builder.Insert(21, "sphinx of ");
Console.WriteLine(builder.ToString());
Console.ReadLine();
}
}
}
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!