C# StringBuilder Append(Char[], Int32, Int32)
Description
StringBuilder Append(Char[], Int32, Int32)
Appends
the string representation of a specified subarray of Unicode characters
to this instance.
Syntax
StringBuilder.Append(Char[], Int32, Int32)
has the following syntax.
public StringBuilder Append(
char[] value,/* w w w . j a va 2 s.c o m*/
int startIndex,
int charCount
)
Parameters
StringBuilder.Append(Char[], Int32, Int32)
has the following parameters.
value
- A character array.startIndex
- The starting position in value.charCount
- The number of characters to append.
Returns
StringBuilder.Append(Char[], Int32, Int32)
method returns A reference to this instance after the append operation has completed.
Example
using System;/* w w w .j a v a 2 s .co m*/
using System.Text;
using System.Globalization;
class Sample
{
public static void Main()
{
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(chars, startPosition, endPosition + 1);
Console.WriteLine(sb);
}
}
}
The code above generates the following result.