The C# Insert function is employed to place a specified string at a specific index position. The indexing starts at 0. Upon insertion of the specified string, a new modified string is returned.
Signature
Example
public string Insert(Int32 first, String second)
Parameters
first: It is used to pass as an index.
The second method is employed to insert the provided string at a specific index.
Return
It returns a new modified string.
C# String Insert Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = s1.Insert(5,"-");
Console.WriteLine(s2);
}
}
Output:
Output
Hello- C#