String.CopyTo 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| CopyTo(Span<Char>) |
이 문자열의 내용을 대상 범위에 복사합니다. |
| CopyTo(Int32, Char[], Int32, Int32) |
이 인스턴스의 지정된 위치에서 유니코드 문자 배열의 지정된 위치에 지정된 수의 문자를 복사합니다. |
CopyTo(Span<Char>)
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
이 문자열의 내용을 대상 범위에 복사합니다.
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))
매개 변수
예외
대상 범위가 원본 문자열보다 짧습니다.
적용 대상
CopyTo(Int32, Char[], Int32, Int32)
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
이 인스턴스의 지정된 위치에서 유니코드 문자 배열의 지정된 위치에 지정된 수의 문자를 복사합니다.
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)
매개 변수
- sourceIndex
- Int32
이 인스턴스에서 복사할 첫 번째 문자의 인덱스입니다.
- destination
- Char[]
이 인스턴스의 문자가 복사되는 유니코드 문자의 배열입니다.
- destinationIndex
- Int32
복사 작업이 시작되는 인덱 destination 스입니다.
- count
- Int32
복사할 destination이 인스턴스의 문자 수입니다.
예외
destination은 null입니다.
sourceIndex, destinationIndex또는 count 음수입니다.
-또는-
sourceIndex 는 현재 인스턴스의 위치를 식별하지 않습니다.
-또는-
destinationIndex 에서는 배열의 유효한 인덱스가 destination 식별되지 않습니다.
-또는-
count 가 이 인스턴스의 끝 부분 문자열 sourceIndex 길이보다 큽
-또는-
count가 배열의 끝 부분 배열 destinationIndex 길이보다 큰 경우 destination
예제
다음 예제에서는 메서드를 보여 줍니다 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
설명
이 메서드는 count 이 인스턴스의 sourceIndex 위치에서 문자 배열의 destinationIndex 위치로 destination 문자를 복사합니다. 이 메서드는 문자 배열의 destination 크기를 조정하지 않습니다. 복사된 문자를 수용할 수 있는 충분한 수의 요소가 있어야 합니다. 그렇지 않으면 메서드가 을 throw합니다 ArgumentOutOfRangeException.
sourceIndex 0 destinationIndex 부터 시작하는 경우