StringBuilder.CopyTo メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(False)> _ Public Sub CopyTo ( _ sourceIndex As Integer, _ destination As Char(), _ destinationIndex As Integer, _ count As Integer _ )
Dim instance As StringBuilder Dim sourceIndex As Integer Dim destination As Char() Dim destinationIndex As Integer Dim count As Integer instance.CopyTo(sourceIndex, destination, destinationIndex, count)
[ComVisibleAttribute(false)] public void CopyTo ( int sourceIndex, char[] destination, int destinationIndex, int count )
[ComVisibleAttribute(false)] public: void CopyTo ( int sourceIndex, array<wchar_t>^ destination, int destinationIndex, int count )
/** @attribute ComVisibleAttribute(false) */ public void CopyTo ( int sourceIndex, char[] destination, int destinationIndex, int count )
ComVisibleAttribute(false) public function CopyTo ( sourceIndex : int, destination : char[], destinationIndex : int, count : int )

例外の種類 | 条件 |
---|---|
ArgumentNullException | destination が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | このインスタンスの長さが、sourceIndex と count を足した値未満です。 または destination の長さが、destinationIndex と count を足した値未満です。 または sourceIndex、destination、destinationIndex、または count が 0 未満です。 |

CopyTo メソッドは、まれに StringBuilder オブジェクトの連続するセクションを効率的に配列にコピーする必要がある場合に使用することを目的としています。配列は、固定サイズで、あらかじめ割り当てられており、再利用でき、可能ならばグローバルにアクセスできるようにする必要があります。
たとえば、アプリケーションで StringBuilder オブジェクトに多くの文字数を割り当て、CopyTo メソッドを使用して、StringBuilder オブジェクトの小さな連続する部分を配列にコピーし、配列内でその部分を処理する場合があります。StringBuilder オブジェクト内のすべてのデータが処理されると、StringBuilder オブジェクトのサイズが 0 に設定され、その循環が繰り返されます。

' 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. Imports System Imports System.Text Imports Microsoft.VisualBasic Class Sample Protected Shared dest(5) As Char Public Shared Sub Main() Dim src As New StringBuilder("abcdefghijklmnopqrstuvwxyz!") dest(1) = ")"c dest(2) = " "c ' Copy the source to the destination in 9 pieces, 3 characters per piece. Console.WriteLine(vbCrLf & "Piece) Data:") Dim ix As Integer For ix = 0 To 8 dest(0) = ix.ToString()(0) src.CopyTo(ix * 3, dest, 3, 3) Console.Write(" ") Console.WriteLine(dest) Next ix End Sub 'Main End Class 'Sample ' '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!
// 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! */
// 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 namespace System; using namespace System::Text; int main() { array<Char>^dest = gcnew array<Char>(6); StringBuilder^ src = gcnew 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! */
// 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. import System.*; import System.Text.*; class Sample { protected static char dest[] = new char[6]; public static void main(String[] args) { StringBuilder src = new StringBuilder("abcdefghijklmnopqrstuvwxyz!"); dest.set_Item(1, (System.Char)')'); dest.set_Item(2, (System.Char)' '); // 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] = ((Int32)ix).ToString().get_Chars(0); src.CopyTo(ix * 3, dest, 3, 3); Console.Write(" "); Console.WriteLine(dest); } } //main } //Sample /* 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! */

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からStringBuilder.CopyTo メソッドを検索する場合は、下記のリンクをクリックしてください。

- StringBuilder.CopyTo メソッドのページへのリンク