C# String Insert

Description

String Insert returns a new string in which a specified string is inserted at a specified index position in this instance.

Syntax

String.Insert has the following syntax.


public string Insert(
  int startIndex,
  string value
)

Parameters

String.Insert has the following parameters.

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

Returns

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

Example

The following console application provides a simple demonstration of the Insert method.


using System;// w  ww  .j a v  a  2 s.  c  om

public class Example {
    public static void Main() 
    {

        String strTarget = "asdf".Insert(1, "value");
        Console.WriteLine(strTarget);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version