System.String.Insert Method

Returns a new string in which a specified string is inserted at a specified index position in this instance.

Syntax

public string Insert (int startIndex, string value)

Parameters

startIndex
The zero-based index position of the insertion.
value
The string to insert.

Returns

A new string that is equivalent to this instance, but with value inserted at position startIndex.

Exceptions

TypeReason
ArgumentNullException value is a null reference.
ArgumentOutOfRangeException startIndex is greater than the length of the current instance.

Remarks

If startIndex is equal to the length of this instance, value is appended to the end of this instance.

Note:

This method does not modify the value of the current instance. Instead, it returns a new string in which value is inserted into the current instance.

For example, the return value of "abc".Insert(2, "XYZ") is "abXYZc".

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0