轉自msdn StringBuilder. CopyTo 方法 |
[ComVisibleAttribute(false)]
public void CopyTo(
int sourceIndex,
char[] destination,
int destinationIndex,
int count
)
參數
sourceIndex
- 型別: System. Int32
此執行個體中的開始位置,為字元的複製來源。 索引以零起始。
- destination
- 型別: System. Char[]
將複製其中字元的陣列。
- destinationIndex
- 型別: System. Int32
destination 中開始複製字元的位置。 索引以零起始。
- count
- 型別: System. Int32
要複製的字元數。
// This example demonstrates the CopyTo(Int32, Char[], Int32, Int32) method.
// Typically the destination array is small, preallocated, and global while
// the StringBuilder is large with programmatically defined data.
// However, for this example both the array and StringBuilder are small
// and the StringBuilder has predefined data.
using System;
using System.Text;
class Sample
{
protected static char[] dest = new char[6];
public static void Main()
{
StringBuilder src = new StringBuilder("abcdefghijklmnopqrstuvwxyz!");
dest[1] = ')';
dest[2] = ' ';
// Copy the source to the destination in 9 pieces, 3 characters per piece.
Console.WriteLine("\nPiece) Data:");
for(int ix = 0; ix < 9; ix++)
{
dest[0] = ix.ToString()[0];
src.CopyTo(ix * 3, dest, 3, 3);
Console.Write(" ");
Console.WriteLine(dest);
}
}
}
/*
This example produces the following results:
Piece) Data:
0) abc
1) def
2) ghi
3) jkl
4) mno
5) pqr
6) stu
7) vwx
8) yz!
*/
沒有留言:
張貼留言