Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

StringBuilder.Append Method (Char[], Int32, Int32)

Appends the string representation of a specified subarray of Unicode characters to the end of this instance.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Function Append ( _
	value As Char(), _
	startIndex As Integer, _
	charCount As Integer _
) As StringBuilder
'Usage
Dim instance As StringBuilder
Dim value As Char()
Dim startIndex As Integer
Dim charCount As Integer
Dim returnValue As StringBuilder

returnValue = instance.Append(value, startIndex, charCount)
public StringBuilder Append (
	char[] value, 
	int startIndex, 
	int charCount
)
public function Append (
	value : char[], 
	startIndex : int, 
	charCount : int
) : StringBuilder
Not applicable.

Parameters

value

A character array.

startIndex

The starting position in value.

charCount

The number of characters to append.

Return Value

A reference to this instance after the append operation has completed.

Exception typeCondition

ArgumentNullException

value is a null reference (Nothing in Visual Basic), and startIndex and charCount are not zero.

ArgumentOutOfRangeException

charCount is less than zero.

-or-

startIndex is less than zero.

-or-

startIndex + charCount is less than the length of value.

-or-

Enlarging the value of this instance would exceed MaxCapacity.

This method appends the specified range of characters in value to the current instance. If value is a null reference (Nothing in Visual Basic) and startIndex and count are both zero, no changes are made.

The capacity of this instance is adjusted as needed.

The following example demonstrates how to append various data type values to a StringBuilder object.

Imports System
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim sep As String = ", "
      Dim head As String = "<<<"
      Dim tail As Char() =  {">"c, ">"c, ">"c}
      Dim dash As Char = "-"c
      Dim obj As [Object] = 0
      
      Dim xBool As Boolean = True
      Dim xByte As Byte = 1
      Dim xInt16 As Short = 2
      Dim xInt32 As Integer = 3
      Dim xInt64 As Long = 4
      Dim xDecimal As [Decimal] = 5
      Dim xSingle As Single = 6.6F
      Dim xDouble As Double = 7.7
      
      ' The following types are not CLS-compliant.
      ' Dim xUInt16 As System.UInt16 = 8
      ' Dim xUInt32 As System.UInt32 = 9
      ' Dim xUInt64 As System.UInt64 = 10
      ' Dim xSByte As System.SByte = - 11
      '
      Dim sb As New StringBuilder()
      
      sb = sb.Append(head)              ' <<<
      sb = sb.Append(head, 2, 1)        ' <<<<
      sb = sb.Append(dash)              ' <<<<-
      sb = sb.Append(dash).Append(dash) ' <<<<---
      sb = sb.Append(xBool).Append(sep)
      sb = sb.Append(obj).Append(sep).Append(xByte).Append(sep)
      sb = sb.Append(xInt16)
      sb = sb.Append(sep)
      sb = sb.Append(xInt32)
      sb = sb.Append(sep)
      sb = sb.Append(xInt64)
      sb = sb.Append(sep)
      sb = sb.Append(xDecimal).Append(sep)
      sb = sb.Append(xSingle).Append(sep).Append(xDouble)
      
      ' The following Append methods are not CLS-compliant.
      ' sb.Append(xUInt16)
      ' sb.Append(xUInt32)
      ' sb.Append(xUInt64)
      ' sb.Append(xSByte)
      '
      sb = sb.Append(dash, 3)           ' ---
      sb = sb.Append(tail)              ' --->>>
      sb = sb.Append(tail, 2, 1)        ' --->>>>
      Dim str As [String] = sb.ToString()
      Console.WriteLine("The appended string is:")
      Console.WriteLine(str)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'The appended string is:
'<<<<---True, 0, 1, 2, 3, 4, 5, 6.6, 7.7--->>>>
'

// This example demonstrates StringBuilder.Append()
import System.*;
import System.Text.*;

class Sample
{
    public static void main(String[] args)
    {
        String sep = ", ";
        String head = "<<<";
        char tail[] =  { '>', '>', '>' };
        char dash = '-';
        Object obj = new Integer(0);

        boolean xBool = true;
        ubyte xByte = 1;
        short xInt16 = 2;
        int xInt32 = 3;
        long xInt64 = 4;
        Decimal xDecimal = new Decimal(5);
        float xSingle = 6.6f;
        double xDouble = 7.7;
        // The following types are not CLS-compliant.
        int xUInt16 = 8;
        int xUInt32 = 9;
        long xUInt64 = 10;
        byte xSByte = -11;
        //
        StringBuilder sb = new StringBuilder();

        sb = sb.Append(head); // <<<
        sb = sb.Append(head, 2, 1); // <<<<
        sb = sb.Append(dash); // <<<<-
        sb = sb.Append(dash).Append(dash); // <<<<---
        sb = sb.Append(xBool).Append(sep);
        sb = sb.Append(obj).Append(sep).Append(xByte).Append(sep);
        sb = sb.Append(xInt16);
        sb = sb.Append(sep);
        sb = sb.Append(xInt32);
        sb = sb.Append(sep);
        sb = sb.Append(xInt64);
        sb = sb.Append(sep);
        sb = sb.Append(xDecimal).Append(sep);
        sb = sb.Append(xSingle).Append(sep).Append(xDouble).Append(sep);
        // The following Append methods are not CLS-compliant.
        sb = sb.Append(xUInt16).Append(sep);
        sb = sb.Append(xUInt32).Append(sep).Append(xUInt64).Append(sep);
        sb = sb.Append(xSByte);
        //
        sb = sb.Append(dash, 3); // ---
        sb = sb.Append(tail); // --->>>
        sb = sb.Append(tail, 2, 1); // --->>>>
        String str = sb.ToString();
        Console.WriteLine("The appended string is:");
        Console.WriteLine(str);
    } //main
} //Sample
/*
This example produces the following results:
The appended string is:
<<<<---True, 0, 1, 2, 3, 4, 5, 6.6, 7.7, 8, 9, 10, -11--->>>>
*/

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft