StringBuilder.CopyTo メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringBuilder.CopyTo メソッドの意味・解説 

StringBuilder.CopyTo メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

このインスタンス指定したセグメントにある文字を、特定の Char 配列指定したセグメントコピーします

名前空間: System.Text
アセンブリ: 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
)

パラメータ

sourceIndex

このインスタンスにおける文字コピー開始位置インデックスが 0 から始まってます。

destination

文字コピー先となる Char 配列

destinationIndex

destination における文字コピー開始位置インデックスが 0 から始まってます。

count

コピーする文字数

例外例外
例外種類条件

ArgumentNullException

destinationnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

このインスタンス長さが、sourceIndexcount足した未満です。

または

destination長さが、destinationIndexcount足した未満です。

または

sourceIndexdestinationdestinationIndex、または count が 0 未満です。

解説解説
使用例使用例

CopyTo メソッドコード例次に示します

' 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!
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

StringBuilder.CopyTo メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringBuilder.CopyTo メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS