String.CopyTo(Int32, Char[], Int32, Int32) Methode
Definition
Kopiert eine angegebene Anzahl von Zeichen von einer angegebenen Position in dieser Instanz an eine angegebene Position in einem Array von Unicode-Zeichen.Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.
public:
void CopyTo(int sourceIndex, cli::array <char> ^ destination, int destinationIndex, int count);
public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count);
member this.CopyTo : int * char[] * int * int -> unit
Public Sub CopyTo (sourceIndex As Integer, destination As Char(), destinationIndex As Integer, count As Integer)
Parameter
- sourceIndex
- Int32
Der Index des ersten Zeichens in dieser Instanz, das kopiert werden soll.The index of the first character in this instance to copy.
- destination
- Char[]
Ein Array von Unicode-Zeichen, in das Zeichen in dieser Instanz kopiert werden.An array of Unicode characters to which characters in this instance are copied.
- destinationIndex
- Int32
Der Index in destination
, bei dem der Kopiervorgang beginnt.The index in destination
at which the copy operation begins.
- count
- Int32
Die Anzahl der Zeichen in dieser Instanz, die nach destination
kopiert werden sollen.The number of characters in this instance to copy to destination
.
Ausnahmen
destination
ist null
.destination
is null
.
sourceIndex
, destinationIndex
oder count
ist ein negativer Wert.sourceIndex
, destinationIndex
, or count
is negative
- oder --or-
sourceIndex
identifiziert keine Position in der aktuellen Instanz.sourceIndex
does not identify a position in the current instance.
- oder --or-
destinationIndex
identifiziert keinen gültigen Index im destination
-Array.destinationIndex
does not identify a valid index in the destination
array.
- oder --or-
count
ist größer als die Länge der Teilzeichenfolge von sourceIndex
bis zum Ende dieser Instanzcount
is greater than the length of the substring from sourceIndex
to the end of this instance
- oder --or-
count
ist größer als die Länge des Teilarrays von destinationIndex
bis zum Ende des destination
-Arrays.count
is greater than the length of the subarray from destinationIndex
to the end of the destination
array.
Beispiele
Das folgende Beispiel veranschaulicht die CopyTo Methode.The following example demonstrates the CopyTo method.
using namespace System;
int main()
{
// Embed an array of characters in a string
String^ strSource = "changed";
array<Char>^destination = {'T','h','e',' ','i','n','i','t','i','a','l',' ','a','r','r','a','y'};
// Print the char array
Console::WriteLine( destination );
// Embed the source string in the destination string
strSource->CopyTo( 0, destination, 4, strSource->Length );
// Print the resulting array
Console::WriteLine( destination );
strSource = "A different string";
// Embed only a section of the source string in the destination
strSource->CopyTo( 2, destination, 3, 9 );
// Print the resulting array
Console::WriteLine( destination );
}
// The example displays the following output:
// The initial array
// The changed array
// Thedifferentarray
using System;
public class CopyToTest {
public static void Main() {
// Embed an array of characters in a string
string strSource = "changed";
char [] destination = { 'T', 'h', 'e', ' ', 'i', 'n', 'i', 't', 'i', 'a', 'l', ' ',
'a', 'r', 'r', 'a', 'y' };
// Print the char array
Console.WriteLine( destination );
// Embed the source string in the destination string
strSource.CopyTo ( 0, destination, 4, strSource.Length );
// Print the resulting array
Console.WriteLine( destination );
strSource = "A different string";
// Embed only a section of the source string in the destination
strSource.CopyTo ( 2, destination, 3, 9 );
// Print the resulting array
Console.WriteLine( destination );
}
}
// The example displays the following output:
// The initial array
// The changed array
// Thedifferentarray
Public Class CopyToTest
Public Shared Sub Main()
' Embed an array of characters in a string
Dim strSource As String = "changed"
Dim destination As Char() = {"T"c, "h"c, "e"c, " "c, "i"c, "n"c, "i"c, _
"t"c, "i"c, "a"c, "l"c, " "c, "a"c, "r"c, "r"c, "a"c, "y"c}
' Print the char array
Console.WriteLine(destination)
' Embed the source string in the destination string
strSource.CopyTo(0, destination, 4, strSource.Length)
' Print the resulting array
Console.WriteLine(destination)
strSource = "A different string"
' Embed only a section of the source string in the destination
strSource.CopyTo(2, destination, 3, 9)
' Print the resulting array
Console.WriteLine(destination)
End Sub
End Class
' The example displays the following output:
' The initial array
' The changed array
' Thedifferentarray
Hinweise
Diese Methode kopiert count
Zeichen von der sourceIndex
Position dieser Instanz an die destinationIndex
Position des destination
Zeichen Arrays.This method copies count
characters from the sourceIndex
position of this instance to the destinationIndex
position of destination
character array. Diese Methode ändert nicht die Größe des destination
Zeichen Arrays. Sie muss über eine ausreichende Anzahl von Elementen verfügen, um die kopierten Zeichen aufnehmen zu können, oder die Methode löst eine aus ArgumentOutOfRangeException .This method does not resize the destination
character array; it must have a sufficient number of elements to accommodate the copied characters or the method throws an ArgumentOutOfRangeException.
sourceIndex
und destinationIndex
sind NULL basiert.sourceIndex
and destinationIndex
are zero-based.