String.CopyTo Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Přetížení
| Name | Description |
|---|---|
| CopyTo(Span<Char>) |
Zkopíruje obsah tohoto řetězce do cílového rozsahu. |
| CopyTo(Int32, Char[], Int32, Int32) |
Zkopíruje zadaný počet znaků ze zadané pozice v této instanci na zadanou pozici v poli znaků Unicode. |
CopyTo(Span<Char>)
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
Zkopíruje obsah tohoto řetězce do cílového rozsahu.
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))
Parametry
Výjimky
Cílové rozpětí je kratší než zdrojový řetězec.
Platí pro
CopyTo(Int32, Char[], Int32, Int32)
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
- Zdroj:
- String.cs
Zkopíruje zadaný počet znaků ze zadané pozice v této instanci na zadanou pozici v poli znaků Unicode.
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)
Parametry
- sourceIndex
- Int32
Index prvního znaku v této instanci, který chcete zkopírovat.
- destination
- Char[]
Pole znaků Unicode, do kterých jsou znaky v této instanci zkopírovány.
- destinationIndex
- Int32
Index, ve destination kterém začíná operace kopírování.
- count
- Int32
Počet znaků v této instanci pro zkopírování do destination.
Výjimky
destination je null.
sourceIndex, destinationIndexnebo count je záporný
nebo
sourceIndex neidentifikuje pozici v aktuální instanci.
nebo
destinationIndex neidentifikuje platný index v destination poli.
nebo
count je větší než délka podřetětěce od sourceIndex do konce této instance.
nebo
count je větší než délka dílčího pole od destinationIndex konce destination pole.
Příklady
Následující příklad ukazuje metodu CopyTo .
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
Poznámky
Tato metoda kopíruje count znaky z sourceIndex pozice této instance do destinationIndex pozice destination pole znaků. Tato metoda nemění velikost destination pole znaků; musí mít dostatečný počet prvků pro přizpůsobení zkopírovaných znaků nebo metoda vyvolá ArgumentOutOfRangeExceptionznak .
sourceIndex a destinationIndex jsou založené na nule.