Share via


String.CopyTo 메서드

이 인스턴스의 지정한 위치에 있는 지정한 수의 문자를 유니코드 문자 배열의 특정 위치에 복사합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Sub CopyTo ( _
    sourceIndex As Integer, _
    destination As Char(), _
    destinationIndex As Integer, _
    count As Integer _
)
‘사용 방법
Dim instance As String
Dim sourceIndex As Integer
Dim destination As Char()
Dim destinationIndex As Integer
Dim count As Integer

instance.CopyTo(sourceIndex, destination, destinationIndex, count)
public void CopyTo (
    int sourceIndex,
    char[] destination,
    int destinationIndex,
    int count
)
public:
void CopyTo (
    int sourceIndex, 
    array<wchar_t>^ destination, 
    int destinationIndex, 
    int count
)
public void CopyTo (
    int sourceIndex, 
    char[] destination, 
    int destinationIndex, 
    int count
)
public function CopyTo (
    sourceIndex : int, 
    destination : char[], 
    destinationIndex : int, 
    count : int
)

매개 변수

  • sourceIndex
    이 인스턴스의 문자 위치입니다.
  • destination
    유니코드 문자 배열입니다.
  • destinationIndex
    destination에 있는 배열 요소입니다.
  • count
    이 인스턴스에서 destination에 복사할 문자의 수입니다.

예외

예외 형식 조건

ArgumentNullException

destination이 Null 참조(Visual Basic의 경우 Nothing)인 경우

ArgumentOutOfRangeException

sourceIndex, destinationIndex 또는 count가 음수인 경우

- 또는 -

부분 문자열의 startIndex부터 이 인스턴스 끝까지의 길이보다 count가 큰 경우

- 또는 -

하위 배열의 destinationIndex부터 destination 끝까지의 길이보다 count가 큰 경우

설명

count 문자는 이 인스턴스의 sourceIndex 위치에서 destination의 destinationIndex 위치로 복사됩니다.

sourceIndex와 destinationIndex는 0부터 시작합니다.

예제

다음 코드 예제에서는 CopyTo 메서드를 사용하는 방법을 보여 줍니다.

Imports System

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 'Main
End Class 'CopyToTest
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 );
    }
}
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 );
}
import System.*;

public class CopyToTest
{
    public static void main(String[] args)
    {
        // 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.get_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);
    } //main
} //CopyToTest
import System;

public class CopyToTest {
    public static function Main() : void {

        // Embed an array of characters in a string
        var strSource : String = "changed";
        var destination : char[] = "The initial array".ToCharArray();

        // 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 );
    }
}
CopyToTest.Main();

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

String 클래스
String 멤버
System 네임스페이스
Char 구조체
Int32 구조체
Insert
Substring