Export (0) Print
Expand All
6 out of 11 rated this helpful - Rate this topic

StringBuilder.Append Method

Appends the string representation of a specified object to the end of this instance.

Overload List

Appends the string representation of a specified Boolean value to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Boolean) As StringBuilder
[C#] public StringBuilder Append(bool);
[C++] public: StringBuilder* Append(bool);
[JScript] public function Append(Boolean) : StringBuilder;

Appends the string representation of a specified 8-bit unsigned integer to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Byte) As StringBuilder
[C#] public StringBuilder Append(byte);
[C++] public: StringBuilder* Append(unsigned char);
[JScript] public function Append(Byte) : StringBuilder;

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Char) As StringBuilder
[C#] public StringBuilder Append(char);
[C++] public: StringBuilder* Append(__wchar_t);
[JScript] public function Append(Char) : StringBuilder;

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Char()) As StringBuilder
[C#] public StringBuilder Append(char[]);
[C++] public: StringBuilder* Append(__wchar_t __gc[]);
[JScript] public function Append(Char[]) : StringBuilder;

Appends the string representation of a specified decimal number to the end of this instance.

[Visual Basic] Overloads Public Function Append(Decimal) As StringBuilder
[C#] public StringBuilder Append(decimal);
[C++] public: StringBuilder* Append(Decimal);
[JScript] public function Append(Decimal) : StringBuilder;

Appends the string representation of a specified double-precision floating-point number to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Double) As StringBuilder
[C#] public StringBuilder Append(double);
[C++] public: StringBuilder* Append(double);
[JScript] public function Append(double) : StringBuilder;

Appends the string representation of a specified 16-bit signed integer to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Short) As StringBuilder
[C#] public StringBuilder Append(short);
[C++] public: StringBuilder* Append(short);
[JScript] public function Append(Int16) : StringBuilder;

Appends the string representation of a specified 32-bit signed integer to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Integer) As StringBuilder
[C#] public StringBuilder Append(int);
[C++] public: StringBuilder* Append(int);
[JScript] public function Append(int) : StringBuilder;

Appends the string representation of a specified 64-bit signed integer to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Long) As StringBuilder
[C#] public StringBuilder Append(long);
[C++] public: StringBuilder* Append(__int64);
[JScript] public function Append(long) : StringBuilder;

Appends the string representation of a specified object to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Object) As StringBuilder
[C#] public StringBuilder Append(object);
[C++] public: StringBuilder* Append(Object*);
[JScript] public function Append(Object) : StringBuilder;

Appends the string representation of a specified 8-bit signed integer to the end of this instance. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(SByte) As StringBuilder
[C#] public StringBuilder Append(sbyte);
[C++] public: StringBuilder* Append(char);
[JScript] public function Append(SByte) : StringBuilder;

Appends the string representation of a specified single-precision floating-point number to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Single) As StringBuilder
[C#] public StringBuilder Append(float);
[C++] public: StringBuilder* Append(float);
[JScript] public function Append(float) : StringBuilder;

Appends a copy of the specified string to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(String) As StringBuilder
[C#] public StringBuilder Append(string);
[C++] public: StringBuilder* Append(String*);
[JScript] public function Append(String) : StringBuilder;

Appends the string representation of a specified 16-bit unsigned integer to the end of this instance. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(UInt16) As StringBuilder
[C#] public StringBuilder Append(ushort);
[C++] public: StringBuilder* Append(unsigned short);
[JScript] public function Append(UInt16) : StringBuilder;

Appends the string representation of a specified 32-bit unsigned integer to the end of this instance. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(UInt32) As StringBuilder
[C#] public StringBuilder Append(uint);
[C++] public: StringBuilder* Append(unsigned int);
[JScript] public function Append(UInt32) : StringBuilder;

Appends the string representation of a specified 64-bit unsigned integer to the end of this instance. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(UInt64) As StringBuilder
[C#] public StringBuilder Append(ulong);
[C++] public: StringBuilder* Append(unsigned __int64);
[JScript] public function Append(UInt64) : StringBuilder;

Appends a specified number of copies of the string representation of a Unicode character to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Char, Integer) As StringBuilder
[C#] public StringBuilder Append(char, int);
[C++] public: StringBuilder* Append(__wchar_t, int);
[JScript] public function Append(Char, int) : StringBuilder;

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(Char(), Integer, Integer) As StringBuilder
[C#] public StringBuilder Append(char[], int, int);
[C++] public: StringBuilder* Append(__wchar_t __gc[], int, int);
[JScript] public function Append(Char[], int, int) : StringBuilder;

Appends a copy of a specified substring to the end of this instance.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Append(String, Integer, Integer) As StringBuilder
[C#] public StringBuilder Append(string, int, int);
[C++] public: StringBuilder* Append(String*, int, int);
[JScript] public function Append(String, int, int) : StringBuilder;

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Append. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' This example demonstrates StringBuilder.Append()
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--->>>>
'

[C#] 
// This example demonstrates StringBuilder.Append()
using System;
using System.Text;

class Sample 
{
    public static void Main() 
    {
    string      sep       = ", ";
    string      head      = "<<<";
    char[]      tail      = {'>', '>', '>'};
    char        dash      = '-';
    Object     obj       = 0;

    bool        xBool     = true;
    byte        xByte     = 1;
    short       xInt16    = 2;
    int         xInt32    = 3;
    long        xInt64    = 4;
    Decimal     xDecimal  = 5;
    float       xSingle   = 6.6F;
    double      xDouble   = 7.7;

// The following types are not CLS-compliant.
    ushort      xUInt16   = 8;
    uint        xUInt32   = 9;
    ulong       xUInt64   = 10;
    sbyte       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);
    }
}
/*
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--->>>>
*/

[C++] 
// This example demonstrates StringBuilder.Append()
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;

int main() 
{
    String*     sep       = S", ";
    String*     head      = S"<<<";
    Char tail[]           = {'>', '>', '>'};
    Char        dash      = '-';
    Object*     obj       = __box(0);

    bool        xBool     = true;
    Byte        xByte     = 1;
    short       xInt16    = 2;
    int         xInt32    = 3;
    long        xInt64    = 4;
    Decimal     xDecimal  = 5;
    float       xSingle   = 6.6F;
    double      xDouble   = 7.7;

// The following types are not CLS-compliant.
    UInt16      xUInt16   = 8;
    UInt32      xUInt32   = 9;
    UInt64      xUInt64   = 10;
    SByte       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(S"The appended string is:");
    Console::WriteLine(str);
}
/*
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--->>>>
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

StringBuilder Class | StringBuilder Members | System.Text Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.