String.CopyTo Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Overloads
| Name | Description |
|---|---|
| CopyTo(Span<Char>) |
Kopieert de inhoud van deze tekenreeks naar het doelbereik. |
| CopyTo(Int32, Char[], Int32, Int32) |
Kopieert een opgegeven aantal tekens van een opgegeven positie in dit exemplaar naar een opgegeven positie in een matrix met Unicode-tekens. |
CopyTo(Span<Char>)
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
Kopieert de inhoud van deze tekenreeks naar het doelbereik.
public:
void CopyTo(Span<char> destination);
public void CopyTo(Span<char> destination);
member this.CopyTo : Span<char> -> unit
Public Sub CopyTo (destination As Span(Of Char))
Parameters
Uitzonderingen
De doelspanne is korter dan de brontekenreeks.
Van toepassing op
CopyTo(Int32, Char[], Int32, Int32)
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
- Bron:
- String.cs
Kopieert een opgegeven aantal tekens van een opgegeven positie in dit exemplaar naar een opgegeven positie in een matrix met Unicode-tekens.
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)
Parameters
- sourceIndex
- Int32
De index van het eerste teken in dit exemplaar dat moet worden gekopieerd.
- destination
- Char[]
Een matrix van Unicode-tekens waarnaar tekens in dit exemplaar worden gekopieerd.
- destinationIndex
- Int32
De index destination waarin de kopieerbewerking begint.
- count
- Int32
Het aantal tekens in dit exemplaar naar destination.
Uitzonderingen
destination is null.
sourceIndex, destinationIndexof count is negatief
– of –
sourceIndex identificeert geen positie in het huidige exemplaar.
– of –
destinationIndex identificeert geen geldige index in de destination matrix.
– of –
count is groter dan de lengte van de subtekenreeks van sourceIndex tot het einde van dit exemplaar
– of –
count is groter dan de lengte van de submatrix van destinationIndex tot het einde van de destination matrix.
Voorbeelden
In het volgende voorbeeld ziet u de CopyTo methode.
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
// Embed an array of characters in a string
let strSource = "changed"
let destination =
[| 'T'; 'h'; 'e'; ' '; 'i'; 'n'; 'i'; 't'; 'i'; 'a'; 'l'; ' ';
'a'; 'r'; 'r'; 'a'; 'y' |]
// Print the char array
printfn $"{destination}"
// Embed the source string in the destination string
strSource.CopyTo( 0, destination, 4, strSource.Length)
// Print the resulting array
printfn $"{destination}"
let strSource2 = "A different string"
// Embed only a section of the source string in the destination
strSource2.CopyTo( 2, destination, 3, 9)
// Print the resulting array
printfn $"{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
Opmerkingen
Met deze methode worden count tekens van de sourceIndex positie van dit exemplaar gekopieerd naar de positie van destinationIndex de destination tekenmatrix. Met deze methode wordt het formaat van de destination tekenmatrix niet aangepast. Er moet voldoende elementen zijn om de gekopieerde tekens te kunnen gebruiken of de methode genereert een ArgumentOutOfRangeException.
sourceIndex en destinationIndex zijn gebaseerd op nul.