C# StringBuilder Insert(Int32, Char[], Int32, Int32)

Description

StringBuilder Insert(Int32, Char[], Int32, Int32) Inserts the string representation of a specified subarray of Unicode characters into this instance at the specified character position.

Syntax

StringBuilder.Insert(Int32, Char[], Int32, Int32) has the following syntax.


public StringBuilder Insert(
  int index,//from  w w  w . j a  v  a2  s.c o m
  char[] value,
  int startIndex,
  int charCount
)

Parameters

StringBuilder.Insert(Int32, Char[], Int32, Int32) has the following parameters.

  • index - The position in this instance where insertion begins.
  • value - A character array.
  • startIndex - The starting index within value.
  • charCount - The number of characters to insert.

Returns

StringBuilder.Insert(Int32, Char[], Int32, Int32) method returns A reference to this instance after the insert operation has completed.

Example

The following example demonstrates the Insert method.


/*  w w w . j a va 2 s  .  c om*/
using System;
using System.Text;

class Sample 
{
    public static void Main() 
    {
        StringBuilder sb = new StringBuilder("from java2s.com");
        char[]      abc       = {'a', 'b', 'c'};
        sb.Insert(3, abc, 1, 2);
        Console.WriteLine(sb.ToString());
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding