StringBuilder.Append 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定对象的字符串表示形式追加到此实例。
重载
| 名称 | 说明 |
|---|---|
| Append(Rune) | |
| Append(StringBuilder) |
将指定字符串生成器的字符串表示形式追加到此实例。 |
| Append(StringBuilder+AppendInterpolatedStringHandler) |
将指定的内插字符串追加到此实例。 |
| Append(UInt16) |
将指定 16 位无符号整数的字符串表示形式追加到此实例。 |
| Append(UInt64) |
将指定的 64 位无符号整数的字符串表示形式追加到此实例。 |
| Append(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler) |
使用指定的格式将指定的内插字符串追加到此实例。 |
| Append(Char*, Int32) |
向此实例追加从指定地址开始的 Unicode 字符数组。 |
| Append(String) |
将指定字符串的副本追加到此实例。 |
| Append(Char[], Int32, Int32) |
将 Unicode 字符的指定子数组的字符串表示形式追加到此实例。 |
| Append(String, Int32, Int32) |
将指定子字符串的副本追加到此实例。 |
| Append(StringBuilder, Int32, Int32) |
将指定字符串生成器中的子字符串的副本追加到此实例。 |
| Append(Char, Int32) |
将 Unicode 字符的字符串表示形式的指定数目追加到此实例。 |
| Append(Single) |
将指定单精度浮点数的字符串表示形式追加到此实例。 |
| Append(UInt32) |
将指定 32 位无符号整数的字符串表示形式追加到此实例。 |
| Append(ReadOnlySpan<Char>) |
将指定只读字符范围的字符串表示形式追加到此实例。 |
| Append(SByte) |
将指定 8 位有符号整数的字符串表示形式追加到此实例。 |
| Append(Boolean) |
将指定布尔值的字符串表示形式追加到此实例。 |
| Append(Byte) |
将指定 8 位无符号整数的字符串表示形式追加到此实例。 |
| Append(Char) |
将指定 Char 对象的字符串表示形式追加到此实例。 |
| Append(Decimal) |
将指定十进制数的字符串表示形式追加到此实例。 |
| Append(Double) |
将指定的双精度浮点数的字符串表示形式追加到此实例。 |
| Append(Char[]) |
将指定数组中 Unicode 字符的字符串表示形式追加到此实例。 |
| Append(Int32) |
将指定 32 位带符号整数的字符串表示形式追加到此实例。 |
| Append(Int64) |
将指定的 64 位有符号整数的字符串表示形式追加到此实例。 |
| Append(Object) |
将指定对象的字符串表示形式追加到此实例。 |
| Append(ReadOnlyMemory<Char>) |
将指定只读字符内存区域的字符串表示形式追加到此实例。 |
| Append(Int16) |
将指定 16 位带符号整数的字符串表示形式追加到此实例。 |
Append(Rune)
public:
System::Text::StringBuilder ^ Append(System::Text::Rune value);
public System.Text.StringBuilder Append(System.Text.Rune value);
member this.Append : System.Text.Rune -> System.Text.StringBuilder
Public Function Append (value As Rune) As StringBuilder
参数
- value
- Rune
返回
适用于
Append(StringBuilder)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定字符串生成器的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Text::StringBuilder ^ value);
public System.Text.StringBuilder Append(System.Text.StringBuilder? value);
public System.Text.StringBuilder Append(System.Text.StringBuilder value);
member this.Append : System.Text.StringBuilder -> System.Text.StringBuilder
Public Function Append (value As StringBuilder) As StringBuilder
参数
- value
- StringBuilder
要追加的字符串生成器。
返回
完成追加作后对此实例的引用。
适用于
Append(StringBuilder+AppendInterpolatedStringHandler)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定的内插字符串追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Text::StringBuilder::AppendInterpolatedStringHandler % handler);
public System.Text.StringBuilder Append(ref System.Text.StringBuilder.AppendInterpolatedStringHandler handler);
member this.Append : AppendInterpolatedStringHandler -> System.Text.StringBuilder
Public Function Append (ByRef handler As StringBuilder.AppendInterpolatedStringHandler) As StringBuilder
参数
要追加的内插字符串。
返回
追加作完成后对此实例的引用。
适用于
Append(UInt16)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
重要
此 API 不符合 CLS。
将指定 16 位无符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::UInt16 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(ushort value);
[<System.CLSCompliant(false)>]
member this.Append : uint16 -> System.Text.StringBuilder
Public Function Append (value As UShort) As StringBuilder
参数
- value
- UInt16
要追加的值。
返回
追加作完成后对此实例的引用。
- 属性
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(UInt16) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 16-bit unsigned integer: ");
sb.Append(UInt16.MinValue).Append(" to ").Append(UInt16.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 16-bit unsigned integer: 0 to 65535
let sb = StringBuilder "The range of a 16-bit unsigned integer: "
sb.Append(UInt16.MinValue).Append(" to ").Append UInt16.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 16-bit unsigned integer: 0 to 65535
Dim sb As New System.Text.StringBuilder("The range of a 16-bit unsigned integer: ")
sb.Append(UInt16.MinValue).Append(" to ").Append(UInt16.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 16-bit unsigned integer: 0 to 65535
该方法 Append(UInt16) 调用 UInt16.ToString(IFormatProvider) 该方法以获取字符串表示形式 value。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(UInt64)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
重要
此 API 不符合 CLS。
将指定的 64 位无符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::UInt64 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(ulong value);
[<System.CLSCompliant(false)>]
member this.Append : uint64 -> System.Text.StringBuilder
Public Function Append (value As ULong) As StringBuilder
参数
- value
- UInt64
要追加的值。
返回
追加作完成后对此实例的引用。
- 属性
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(UInt64) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 64-bit unsigned integer: ");
sb.Append(UInt64.MinValue).Append(" to ").Append(UInt64.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 64-bit unsigned integer: 0 to 18446744073709551615
let sb = StringBuilder "The range of a 64-bit unsigned integer: "
sb.Append(UInt64.MinValue).Append(" to ").Append UInt64.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 64-bit unsigned integer: 0 to 18446744073709551615
Dim sb As New System.Text.StringBuilder("The range of a 64-bit unsigned integer: ")
sb.Append(UInt64.MinValue).Append(" to ").Append(UInt64.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 64-bit unsigned integer: 0 to 18446744073709551615
该方法 Append(UInt64) 调用 UInt64.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
使用指定的格式将指定的内插字符串追加到此实例。
public:
System::Text::StringBuilder ^ Append(IFormatProvider ^ provider, System::Text::StringBuilder::AppendInterpolatedStringHandler % handler);
public System.Text.StringBuilder Append(IFormatProvider? provider, ref System.Text.StringBuilder.AppendInterpolatedStringHandler handler);
member this.Append : IFormatProvider * AppendInterpolatedStringHandler -> System.Text.StringBuilder
Public Function Append (provider As IFormatProvider, ByRef handler As StringBuilder.AppendInterpolatedStringHandler) As StringBuilder
参数
- provider
- IFormatProvider
提供区域性特定的格式设置信息的对象。
要追加的内插字符串。
返回
追加作完成后对此实例的引用。
适用于
Append(Char*, Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
向此实例追加从指定地址开始的 Unicode 字符数组。
public:
System::Text::StringBuilder ^ Append(char* value, int valueCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public System.Text.StringBuilder Append(char* value, int valueCount);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(char* value, int valueCount);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
member this.Append : nativeptr<char> * int -> System.Text.StringBuilder
[<System.CLSCompliant(false)>]
member this.Append : nativeptr<char> * int -> System.Text.StringBuilder
参数
- value
- Char*
指向字符数组的指针。
- valueCount
- Int32
数组中的字符数。
返回
追加作完成后对此实例的引用。
- 属性
例外
value 为 null 指针。
注解
此方法将 valueCount 从地址 value 开始的字符追加到当前实例。
该方法 Append(Char*, Int32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,并且不必将返回值分配给对象 StringBuilder 。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
适用于
Append(String)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定字符串的副本追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::String ^ value);
public System.Text.StringBuilder Append(string value);
public System.Text.StringBuilder Append(string? value);
member this.Append : string -> System.Text.StringBuilder
Public Function Append (value As String) As StringBuilder
参数
- value
- String
要追加的字符串。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(String) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
bool flag = false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The value of the flag is ").Append(flag).Append(".");
Console.WriteLine(sb.ToString());
// The example displays the following output:
// The value of the flag is False.
let flag = false
let sb = StringBuilder()
sb.Append("The value of the flag is ").Append(flag).Append "." |> ignore
printfn $"{sb}"
// The example displays the following output:
// The value of the flag is False.
Dim flag As Boolean = false
Dim sb As New System.Text.StringBuilder
sb.Append("The value of the flag is ").Append(flag).Append(".")
Console.WriteLine(sb.ToString())
' The example displays the following output:
' The value of the flag is False.
null如果是value,则不进行更改。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Char[], Int32, Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将 Unicode 字符的指定子数组的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(cli::array <char> ^ value, int startIndex, int charCount);
public System.Text.StringBuilder Append(char[] value, int startIndex, int charCount);
public System.Text.StringBuilder Append(char[]? value, int startIndex, int charCount);
member this.Append : char[] * int * int -> System.Text.StringBuilder
Public Function Append (value As Char(), startIndex As Integer, charCount As Integer) As StringBuilder
参数
- value
- Char[]
字符数组。
- startIndex
- Int32
起始位置。value
- charCount
- Int32
要追加的字符数。
返回
追加作完成后对此实例的引用。
例外
value是null,且startIndexcharCount不为零。
charCount 小于零。
-或-
startIndex 小于零。
-或-
startIndex
+
charCount 大于长度 value。
-或-
扩大此实例的值将超出 MaxCapacity。
注解
此方法将指定的字符 value 范围追加到当前实例。 如果value为零null且countstartIndex均为零,则不进行任何更改。
该方法 Append(Char[], Int32, Int32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
char[] chars = { 'a', 'b', 'c', 'd', 'e'};
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int startPosition = Array.IndexOf(chars, 'a');
int endPosition = Array.IndexOf(chars, 'c');
if (startPosition >= 0 && endPosition >= 0) {
sb.Append("The array from positions ").Append(startPosition).
Append(" to ").Append(endPosition).Append(" contains ").
Append(chars, startPosition, endPosition + 1).Append(".");
Console.WriteLine(sb);
}
// The example displays the following output:
// The array from positions 0 to 2 contains abc.
let chars = [| 'a'; 'b'; 'c'; 'd'; 'e' |]
let sb = StringBuilder()
let startPosition = Array.IndexOf(chars, 'a')
let endPosition = Array.IndexOf(chars, 'c')
if startPosition >= 0 && endPosition >= 0 then
sb
.Append("The array from positions ")
.Append(startPosition)
.Append(" to ")
.Append(endPosition)
.Append(" contains ")
.Append(chars, startPosition, endPosition + 1)
.Append "."
|> ignore
printfn $"{sb}"
// The example displays the following output:
// The array from positions 0 to 2 contains abc.
Dim chars() As Char = { "a"c, "b"c, "c"c, "d"c, "e"c}
Dim sb As New System.Text.StringBuilder()
Dim startPosition As Integer = Array.IndexOf(chars, "a"c)
Dim endPosition As Integer = Array.IndexOf(chars, "c"c)
If startPosition >= 0 AndAlso endPosition >= 0 Then
sb.Append("The array from positions ").Append(startPosition).
Append(" to ").Append(endPosition).Append(" contains ").
Append(chars, startPosition, endPosition + 1).Append(".")
Console.WriteLine(sb)
End If
' The example displays the following output:
' The array from positions 0 to 2 contains abc.
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(String, Int32, Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定子字符串的副本追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::String ^ value, int startIndex, int count);
public System.Text.StringBuilder Append(string value, int startIndex, int count);
public System.Text.StringBuilder Append(string? value, int startIndex, int count);
member this.Append : string * int * int -> System.Text.StringBuilder
Public Function Append (value As String, startIndex As Integer, count As Integer) As StringBuilder
参数
- value
- String
包含要追加的子字符串的字符串。
- startIndex
- Int32
子字符串的 value起始位置。
- count
- Int32
要追加的字符 value 数。
返回
追加作完成后对此实例的引用。
例外
value是null,且startIndexcount不为零。
注解
此方法将指定的字符 value 范围追加到当前实例。 如果value为零null且countstartIndex均为零,则不进行任何更改。
该方法 Append(String, Int32, Int32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
string str = "First;George Washington;1789;1797";
int index = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int length = str.IndexOf(';', index);
sb.Append(str, index, length).Append(" President of the United States: ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(", from ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(" to ");
index += length + 1;
sb.Append(str, index, str.Length - index);
Console.WriteLine(sb);
// The example displays the following output:
// First President of the United States: George Washington, from 1789 to 1797
let str = "First;George Washington;1789;1797"
let mutable index = 0
let sb = StringBuilder()
let length = str.IndexOf(';', index)
sb.Append(str, index, length).Append " President of the United States: "
|> ignore
index <- index + length + 1
let length = str.IndexOf(';', index) - index
sb.Append(str, index, length).Append ", from " |> ignore
index <- index + length + 1
let length = str.IndexOf(';', index) - index
sb.Append(str, index, length).Append " to " |> ignore
index <- index + length + 1
sb.Append(str, index, str.Length - index) |> ignore
printfn $"{sb}"
// The example displays the following output:
// First President of the United States: George Washington, from 1789 to 1797
Dim str As String = "First;George Washington;1789;1797"
Dim index As Integer = 0
Dim sb As New System.Text.StringBuilder()
Dim length As Integer = str.IndexOf(";"c, index)
sb.Append(str, index, length).Append(" President of the United States: ")
index += length + 1
length = str.IndexOf(";"c, index) - index
sb.Append(str, index, length).Append(", from ")
index += length + 1
length = str.IndexOf(";"c, index) - index
sb.Append(str, index, length).Append(" to ")
index += length + 1
sb.Append(str, index, str.Length - index)
Console.WriteLine(sb)
' The example displays the following output:
' First President of the United States: George Washington, from 1789 to 1797
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(StringBuilder, Int32, Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定字符串生成器中的子字符串的副本追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Text::StringBuilder ^ value, int startIndex, int count);
public System.Text.StringBuilder Append(System.Text.StringBuilder? value, int startIndex, int count);
public System.Text.StringBuilder Append(System.Text.StringBuilder value, int startIndex, int count);
member this.Append : System.Text.StringBuilder * int * int -> System.Text.StringBuilder
Public Function Append (value As StringBuilder, startIndex As Integer, count As Integer) As StringBuilder
参数
- value
- StringBuilder
包含要追加的子字符串的字符串生成器。
- startIndex
- Int32
子字符串的 value起始位置。
- count
- Int32
要追加的字符 value 数。
返回
追加作完成后对此实例的引用。
适用于
Append(Char, Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将 Unicode 字符的字符串表示形式的指定数目追加到此实例。
public:
System::Text::StringBuilder ^ Append(char value, int repeatCount);
public System.Text.StringBuilder Append(char value, int repeatCount);
member this.Append : char * int -> System.Text.StringBuilder
Public Function Append (value As Char, repeatCount As Integer) As StringBuilder
参数
- value
- Char
要追加的字符。
- repeatCount
- Int32
要追加 value的次数。
返回
追加作完成后对此实例的引用。
例外
内存不足。
注解
该方法 Append(Char, Int32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).AppendFormat("{0:C2}", value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
// *****$1,346.19*****
let value = 1346.19m
let sb = StringBuilder()
sb.Append('*', 5).AppendFormat("{0:C2}", value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
// *****$1,346.19*****
Dim value As Decimal = 1346.19d
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).AppendFormat("{0:C2}", value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
' *****$1,346.19*****
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Single)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定单精度浮点数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(float value);
public System.Text.StringBuilder Append(float value);
member this.Append : single -> System.Text.StringBuilder
Public Function Append (value As Single) As StringBuilder
参数
- value
- Single
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Single) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
float value = 1034769.47f;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
// *****1034769.47*****
let value = 1034769.47f
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
// *****1034769.47*****
Dim value As Single = 1034769.47
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
' *****1034769.47*****
该方法 Append(Single) 调用 Single.ToString 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(UInt32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
重要
此 API 不符合 CLS。
将指定 32 位无符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::UInt32 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(uint value);
[<System.CLSCompliant(false)>]
member this.Append : uint32 -> System.Text.StringBuilder
Public Function Append (value As UInteger) As StringBuilder
参数
- value
- UInt32
要追加的值。
返回
追加作完成后对此实例的引用。
- 属性
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(UInt32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 32-bit unsigned integer: ");
sb.Append(UInt32.MinValue).Append(" to ").Append(UInt32.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 32-bit unsigned integer: 0 to 4294967295
let sb = StringBuilder "The range of a 32-bit unsigned integer: "
sb.Append(UInt32.MinValue).Append(" to ").Append UInt32.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 32-bit unsigned integer: 0 to 4294967295
Dim sb As New System.Text.StringBuilder("The range of a 32-bit unsigned integer: ")
sb.Append(UInt32.MinValue).Append(" to ").Append(UInt32.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 32-bit unsigned integer: 0 to 4294967295
UInt32.ToString调用Append(UInt32)该方法以获取当前区域性的字符串表示形式value。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(ReadOnlySpan<Char>)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定只读字符范围的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(ReadOnlySpan<char> value);
public System.Text.StringBuilder Append(ReadOnlySpan<char> value);
member this.Append : ReadOnlySpan<char> -> System.Text.StringBuilder
Public Function Append (value As ReadOnlySpan(Of Char)) As StringBuilder
参数
- value
- ReadOnlySpan<Char>
要追加的只读字符范围。
返回
完成追加作后对此实例的引用。
适用于
Append(SByte)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
重要
此 API 不符合 CLS。
将指定 8 位有符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::SByte value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(sbyte value);
[<System.CLSCompliant(false)>]
member this.Append : sbyte -> System.Text.StringBuilder
Public Function Append (value As SByte) As StringBuilder
参数
- value
- SByte
要追加的值。
返回
追加作完成后对此实例的引用。
- 属性
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(SByte) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of an 8-bit signed integer: ");
sb.Append(SByte.MinValue).Append(" to ").Append(SByte.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of an 8-bit unsigned integer: -128 to 127
let sb = StringBuilder "The range of an 8-bit signed integer: "
sb.Append(SByte.MinValue).Append(" to ").Append SByte.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of an 8-bit unsigned integer: -128 to 127
Dim sb As New System.Text.StringBuilder("The range of an 8-bit signed integer: ")
sb.Append(SByte.MinValue).Append(" to ").Append(SByte.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of an 8-bit unsigned integer: -128 to 127
该方法 Append(SByte) 调用 SByte.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Boolean)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定布尔值的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(bool value);
public System.Text.StringBuilder Append(bool value);
member this.Append : bool -> System.Text.StringBuilder
Public Function Append (value As Boolean) As StringBuilder
参数
- value
- Boolean
要追加的布尔值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Boolean) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
bool flag = false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The value of the flag is ").Append(flag).Append(".");
Console.WriteLine(sb.ToString());
// The example displays the following output:
// The value of the flag is False.
let flag = false
let sb = StringBuilder()
sb.Append("The value of the flag is ").Append(flag).Append "." |> ignore
printfn $"{sb}"
// The example displays the following output:
// The value of the flag is False.
Dim flag As Boolean = false
Dim sb As New System.Text.StringBuilder
sb.Append("The value of the flag is ").Append(flag).Append(".")
Console.WriteLine(sb.ToString())
' The example displays the following output:
' The value of the flag is False.
该方法 Append(Boolean) 调用 Boolean.ToString() 该方法以获取字符串表示形式 value。 此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Byte)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定 8 位无符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Byte value);
public System.Text.StringBuilder Append(byte value);
member this.Append : byte -> System.Text.StringBuilder
Public Function Append (value As Byte) As StringBuilder
参数
- value
- Byte
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Byte) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
Byte[] bytes = { 16, 132, 27, 253 };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var value in bytes)
sb.Append(value).Append(" ");
Console.WriteLine("The byte array: {0}", sb.ToString());
// The example displays the following output:
// The byte array: 16 132 27 253
let bytes = [| 16uy; 132uy; 27uy; 253uy |]
let sb = StringBuilder()
for value in bytes do
sb.Append(value).Append " " |> ignore
printfn $"The byte array: {sb}"
// The example displays the following output:
// The byte array: 16 132 27 253
Dim bytes() As Byte = { 16, 132, 27, 253 }
Dim sb As New System.Text.StringBuilder()
For Each value In bytes
sb.Append(value).Append(" ")
Next
Console.WriteLine("The byte array: {0}", sb.ToString())
' The example displays the following output:
' The byte array: 16 132 27 253
该方法 Append(Byte) 调用 ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Char)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定 Char 对象的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(char value);
public System.Text.StringBuilder Append(char value);
member this.Append : char -> System.Text.StringBuilder
Public Function Append (value As Char) As StringBuilder
参数
- value
- Char
要追加的 UTF-16 编码代码单元。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Char) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
string str = "Characters in a string.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var ch in str)
sb.Append(" '").Append(ch).Append("' ");
Console.WriteLine("Characters in the string:");
Console.WriteLine(" {0}", sb);
// The example displays the following output:
// Characters in the string:
// 'C' 'h' 'a' 'r' 'a' 'c' 't' 'e' 'r' 's' ' ' 'i' 'n' ' ' 'a' ' ' 's' 't' 'r' 'i' 'n' 'g' '.'
let str = "Characters in a string."
let sb = StringBuilder()
for ch in str do
sb.Append(" '").Append(ch).Append "' " |> ignore
printfn "Characters in the string:"
printfn $" {sb}"
// The example displays the following output:
// Characters in the string:
// 'C' 'h' 'a' 'r' 'a' 'c' 't' 'e' 'r' 's' ' ' 'i' 'n' ' ' 'a' ' ' 's' 't' 'r' 'i' 'n' 'g' '.'
Dim str As String = "Characters in a string."
Dim sb As New System.Text.StringBuilder()
For Each ch In str
sb.Append(" '").Append(ch).Append("' ")
Next
Console.WriteLine("Characters in the string:")
Console.WriteLine(" {0}", sb)
' The example displays the following output:
' Characters in the string:
' 'C' 'h' 'a' 'r' 'a' 'c' 't' 'e' 'r' 's' ' ' 'i' 'n' ' ' 'a' ' ' 's' 't' 'r' 'i' 'n' 'g' '.'
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Decimal)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定十进制数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Decimal value);
public System.Text.StringBuilder Append(decimal value);
member this.Append : decimal -> System.Text.StringBuilder
Public Function Append (value As Decimal) As StringBuilder
参数
- value
- Decimal
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Decimal) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
// *****1346.19*****
let value = 1346.19m
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
// *****1346.19*****
Dim value As Decimal = 1346.19d
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
' *****1346.19*****
该方法 Append(Decimal) 调用 Decimal.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Double)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定的双精度浮点数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(double value);
public System.Text.StringBuilder Append(double value);
member this.Append : double -> System.Text.StringBuilder
Public Function Append (value As Double) As StringBuilder
参数
- value
- Double
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Double) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
double value = 1034769.47;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
// *****1034769.47*****
let value = 1034769.47
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
// *****1034769.47*****
Dim value As Double = 1034769.47
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
' *****1034769.47*****
该方法 Append(Double) 调用 Double.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Char[])
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定数组中 Unicode 字符的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(cli::array <char> ^ value);
public System.Text.StringBuilder Append(char[] value);
public System.Text.StringBuilder Append(char[]? value);
member this.Append : char[] -> System.Text.StringBuilder
Public Function Append (value As Char()) As StringBuilder
参数
- value
- Char[]
要追加的字符数组。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
此方法将指定数组中的所有字符追加到当前实例中,其顺序与在当前实例中 value显示的顺序相同。
null如果是value,则不进行更改。
该方法 Append(Char[]) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
char[] chars = { 'a', 'e', 'i', 'o', 'u' };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The characters in the array: ").Append(chars);
Console.WriteLine(sb);
// The example displays the following output:
// The characters in the array: aeiou
let chars = [| 'a'; 'e'; 'i'; 'o'; 'u' |]
let sb = StringBuilder()
sb.Append("The characters in the array: ").Append chars |> ignore
printfn $"{sb}"
// The example displays the following output:
// The characters in the array: aeiou
Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c }
Dim sb As New System.Text.StringBuilder()
sb.Append("The characters in the array: ").Append(chars)
Console.WriteLine(sb)
' The example displays the following output:
' The characters in the array: aeiou
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
适用于
Append(Int32)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定 32 位带符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(int value);
public System.Text.StringBuilder Append(int value);
member this.Append : int -> System.Text.StringBuilder
Public Function Append (value As Integer) As StringBuilder
参数
- value
- Int32
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Int32) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 32-bit integer: ");
sb.Append(Int32.MinValue).Append(" to ").Append(Int32.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 32-bit integer: -2147483648 to 2147483647
let sb = StringBuilder "The range of a 32-bit integer: "
sb.Append(Int32.MinValue).Append(" to ").Append Int32.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 32-bit integer: -2147483648 to 2147483647
Dim sb As New System.Text.StringBuilder("The range of a 32-bit integer: ")
sb.Append(Int32.MinValue).Append(" to ").Append(Int32.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 32-bit integer: -2147483648 to 2147483647
该方法 Append(Int32) 调用 Int32.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Int64)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定的 64 位有符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(long value);
public System.Text.StringBuilder Append(long value);
member this.Append : int64 -> System.Text.StringBuilder
Public Function Append (value As Long) As StringBuilder
参数
- value
- Int64
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Int64) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 64-bit integer: ");
sb.Append(Int64.MinValue).Append(" to ").Append(Int64.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 64-bit integer: -9223372036854775808 to 9223372036854775807
let sb = StringBuilder "The range of a 64-bit integer: "
sb.Append(Int64.MinValue).Append(" to ").Append Int64.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 64-bit integer: -9223372036854775808 to 9223372036854775807
Dim sb As New System.Text.StringBuilder("The range of a 64-bit integer: ")
sb.Append(Int64.MinValue).Append(" to ").Append(Int64.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 64-bit integer: -9223372036854775808 to 9223372036854775807
该方法 Append(Int64) 调用 Int64.ToString(IFormatProvider) 获取当前区域性的 value 字符串表示形式。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(Object)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定对象的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(System::Object ^ value);
public System.Text.StringBuilder Append(object value);
public System.Text.StringBuilder Append(object? value);
member this.Append : obj -> System.Text.StringBuilder
Public Function Append (value As Object) As StringBuilder
参数
- value
- Object
要追加的对象。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Object) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。 它定义一个 Dog 类,创建一个 Dog 对象,并对该方法进行三次调用 Append ,以创建一个包含狗的名称和品种的字符串。
using System;
public class Dog
{
private string dogBreed;
private string dogName;
public Dog(string name, string breed)
{
this.dogName = name;
this.dogBreed = breed;
}
public string Breed {
get { return this.dogBreed; }
}
public string Name {
get { return this.dogName; }
}
public override string ToString()
{
return this.dogName;
}
}
public class Example
{
public static void Main()
{
Dog dog1 = new Dog("Yiska", "Alaskan Malamute");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(dog1).Append(", Breed: ").Append(dog1.Breed);
Console.WriteLine(sb);
}
}
// The example displays the following output:
// Yiska, Breed: Alaskan Malamute
open System.Text
type Dog(name: string, breed: string) =
member _.Name = name
member _.Breed = breed
override _.ToString() = name
let dog1 = Dog("Yiska", "Alaskan Malamute")
let sb = StringBuilder()
sb.Append(dog1).Append(", Breed: ").Append dog1.Breed |> printfn "%O"
// The example displays the following output:
// Yiska, Breed: Alaskan Malamute
Public Class Dog
Private dogBreed As String
Private dogName As String
Public Sub New(name As String, breed As String)
Me.dogName = name
Me.dogBreed = breed
End Sub
Public ReadOnly Property Breed As String
Get
Return Me.dogBreed
End Get
End Property
Public ReadOnly Property Name As String
Get
Return Me.dogName
End Get
End Property
Public Overrides Function ToString() As String
Return Me.dogName
End Function
End Class
Module Example
Public Sub Main()
Dim dog1 As New Dog("Yiska", "Alaskan Malamute")
Dim sb As New System.Text.StringBuilder()
sb.Append(dog1).Append(", Breed: ").Append(dog1.Breed)
Console.WriteLine(sb)
End Sub
End Module
' The example displays the following output:
' Yiska, Breed: Alaskan Malamute
该方法 Append(Object) 调用 Object.ToString 该方法以获取字符串表示形式 value。
null如果是value,则不会对StringBuilder对象进行更改。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。
另请参阅
适用于
Append(ReadOnlyMemory<Char>)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定只读字符内存区域的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(ReadOnlyMemory<char> value);
public System.Text.StringBuilder Append(ReadOnlyMemory<char> value);
member this.Append : ReadOnlyMemory<char> -> System.Text.StringBuilder
Public Function Append (value As ReadOnlyMemory(Of Char)) As StringBuilder
参数
- value
- ReadOnlyMemory<Char>
要追加的只读字符内存区域。
返回
完成追加作后对此实例的引用。
适用于
Append(Int16)
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
- Source:
- StringBuilder.cs
将指定 16 位带符号整数的字符串表示形式追加到此实例。
public:
System::Text::StringBuilder ^ Append(short value);
public System.Text.StringBuilder Append(short value);
member this.Append : int16 -> System.Text.StringBuilder
Public Function Append (value As Short) As StringBuilder
参数
- value
- Int16
要追加的值。
返回
追加作完成后对此实例的引用。
例外
扩大此实例的值将超出 MaxCapacity。
注解
该方法 Append(Int16) 修改此类的现有实例;它不返回新的类实例。 因此,您可以对现有引用调用方法或属性,不必将返回值 StringBuilder 分配给对象,如以下示例所示。
System.Text.StringBuilder sb = new
System.Text.StringBuilder("The range of a 16-bit integer: ");
sb.Append(Int16.MinValue).Append(" to ").Append(Int16.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
// The range of a 16-bit integer: -32768 to 32767
let sb = StringBuilder "The range of a 16-bit integer: "
sb.Append(Int16.MinValue).Append(" to ").Append Int16.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
// The range of a 16-bit integer: -32768 to 32767
Dim sb As New System.Text.StringBuilder("The range of a 16-bit integer: ")
sb.Append(Int16.MinValue).Append(" to ").Append(Int16.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
' The range of a 16-bit integer: -32768 to 32767
该方法 Append(Int16) 调用 Int16.ToString(IFormatProvider) 该方法以获取当前区域性的字符串表示形式 value 。 若要控制其 value格式,请调用 AppendFormat 该方法。
此实例的容量会根据需要进行调整。
调用方说明
在 .NET Core 和 .NET Framework 4.0 及更高版本中,通过调用StringBuilder(Int32, Int32)构造函数实例化StringBuilder对象时,实例的StringBuilder长度和容量都可以超出其MaxCapacity属性的值。 尤其是在调用 Append(String) 和 AppendFormat(String, Object) 方法以追加小字符串时,会出现这种情况。