次の方法で共有


String.Copy メソッド

指定した String と同じ値を使用して、 String の新しいインスタンスを作成します。

Public Shared Function Copy( _
   ByVal str As String _) As String
[C#]
public static string Copy(stringstr);
[C++]
public: static String* Copy(String* str);
[JScript]
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'
'

[C#] 
// 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'
*/

[C++] 
// Sample for String::Copy()
#using <mscorlib.dll>

using namespace System;

int main() {
    String* str1 = S"abc";
    String* str2 = S"xyz";
    Console::WriteLine(S"1) str1 = '{0}'", str1);
    Console::WriteLine(S"2) str2 = '{0}'", str2);
    Console::WriteLine(S"Copy...");
    str2 = String::Copy(str1);
    Console::WriteLine(S"3) str1 = '{0}'", str1);
    Console::WriteLine(S"4) str2 = '{0}'", str2);
}
/*
This example produces the following results:
1) str1 = 'abc'
2) str2 = 'xyz'
Copy...
3) str1 = 'abc'
4) str2 = 'abc'
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

String クラス | String メンバ | System 名前空間 | Empty | DBNull