String.CopyTo 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| CopyTo(Span<Char>) |
이 문자열의 내용을 대상 범위에 복사합니다. |
| CopyTo(Int32, Char[], Int32, Int32) |
이 인스턴스의 지정한 위치에 있는 지정한 수의 문자를 유니코드 문자 배열의 특정 위치에 복사합니다. |
CopyTo(Span<Char>)
- 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
이 인스턴스의 지정한 위치에 있는 지정한 수의 문자를 유니코드 문자 배열의 특정 위치에 복사합니다.
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 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
// 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 위치에서 문자 배열의 destination 위치로 destinationIndex 문자를 복사합니다. 이 메서드는 문자 배열의 destination 크기를 조정하지 않습니다. 복사된 문자를 수용할 수 있는 요소 수가 충분해야 합니다. 그렇지 않으면 메서드가 을 ArgumentOutOfRangeExceptionthrow합니다.
sourceIndex 및 destinationIndex 는 0부터 시작합니다.