Share via


String.Copy 메서드

지정된 String과 동일한 값을 갖는 String의 새 인스턴스를 만듭니다.

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

구문

‘선언
Public Shared Function Copy ( _
    str As String _
) As String
‘사용 방법
Dim str As String
Dim returnValue As String

returnValue = String.Copy(str)
public static string Copy (
    string str
)
public:
static String^ Copy (
    String^ str
)
public static String Copy (
    String str
)
public static function Copy (
    str : String
) : String

매개 변수

  • str
    복사할 String입니다.

반환 값

str와 동일한 값을 갖는 새 String을 반환합니다.

예외

예외 형식 조건

ArgumentNullException

str가 Null 참조(Visual Basic의 경우 Nothing)인 경우

예제

다음 코드 예제에서는 두 개의 변수에서 참조하는 서로 다른 두 문자열을 표시하고, 첫 번째 문자열의 복사본을 만들고, 두 번째 변수에 새 문자열에 대한 참조를 지정한 다음 변수에서 참조하는 두 문자열을 표시하여 이 둘이 동일함을 보여 줍니다.

' Sample for String.Copy()
Imports System

Class Sample
   
   Public Shared Sub Main()
      Dim str1 As String = "abc"
      Dim str2 As String = "xyz"
      Console.WriteLine("1) str1 = '{0}'", str1)
      Console.WriteLine("2) str2 = '{0}'", str2)
      Console.WriteLine("Copy...")
      str2 = [String].Copy(str1)
      Console.WriteLine("3) str1 = '{0}'", str1)
      Console.WriteLine("4) str2 = '{0}'", str2)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'1) str1 = 'abc'
'2) str2 = 'xyz'
'Copy...
'3) str1 = 'abc'
'4) str2 = 'abc'
'
// Sample for String.Copy()
using System;

class Sample {
    public static void Main() {
    string str1 = "abc";
    string str2 = "xyz";
    Console.WriteLine("1) str1 = '{0}'", str1);
    Console.WriteLine("2) str2 = '{0}'", str2);
    Console.WriteLine("Copy...");
    str2 = String.Copy(str1);
    Console.WriteLine("3) str1 = '{0}'", str1);
    Console.WriteLine("4) str2 = '{0}'", str2);
    }
}
/*
This example produces the following results:
1) str1 = 'abc'
2) str2 = 'xyz'
Copy...
3) str1 = 'abc'
4) str2 = 'abc'
*/
// Sample for String::Copy()
using namespace System;
int main()
{
   String^ str1 = "abc";
   String^ str2 = "xyz";
   Console::WriteLine( "1) str1 = '{0}'", str1 );
   Console::WriteLine( "2) str2 = '{0}'", str2 );
   Console::WriteLine( "Copy..." );
   str2 = String::Copy( str1 );
   Console::WriteLine( "3) str1 = '{0}'", str1 );
   Console::WriteLine( "4) str2 = '{0}'", str2 );
}

/*
This example produces the following results:
1) str1 = 'abc'
2) str2 = 'xyz'
Copy...
3) str1 = 'abc'
4) str2 = 'abc'
*/
// Sample for String.Copy()
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String str1 = "abc";
        String str2 = "xyz";
        Console.WriteLine("1) str1 = '{0}'", str1);
        Console.WriteLine("2) str2 = '{0}'", str2);
        Console.WriteLine("Copy...");
        str2 = String.Copy(str1);
        Console.WriteLine("3) str1 = '{0}'", str1);
        Console.WriteLine("4) str2 = '{0}'", str2);
    } //main
} //Sample
/*
This example produces the following results:
1) str1 = 'abc'
2) str2 = 'xyz'
Copy...
3) str1 = 'abc'
4) str2 = 'abc'
*/

플랫폼

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 네임스페이스
Empty
DBNull 클래스