Open In App

C# | Insert() Method

In C#, Insert() method is a String method. It is used to return a new string in which a specified string is inserted at a specified index position in the current string instance.

Syntax:



public string Insert(int Indexvalue, string value)

Explanation:

Exceptions:



Note: This method always returns a new string which is modified with value inserted at the specified position. The return value type of Insert() method is System.String. If Indexvalue is equal to the length of the current instance, then the value is appended to the end of this instance.

Example:

Input : str  = "GeeksForGeeks"
        str.Insert(5, "GFG");
Output: GeeksGFGForGeeks

Input : str  = "GeeksForGeeks"
        str.Insert(8, " ");
Output: GeeksFor Geeks

Below are the programs to illustrate the Insert() Method :

Reference: https://msdn.microsoft.com/en-us/library/system.string.insert


Article Tags :
C#