String.Insert Method (Int32, String)
Returns a new string in which a specified string is inserted at a specified index position in this instance.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- startIndex
-
Type:
System.Int32
The zero-based index position of the insertion.
- value
-
Type:
System.String
The string to insert.
Return Value
Type: System.StringA new string that is equivalent to this instance, but with value inserted at position startIndex.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is null. |
| ArgumentOutOfRangeException | startIndex is negative or greater than the length of this instance. |
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".
The following example inserts a space character in the fourth character position (the character at index 3) of a string.
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
