Export (0) Print
Expand All

String.Copy Method

Creates a new instance of String with the same value as a specified String.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function Copy ( _
	str As String _
) As String

Parameters

str
Type: System.String
The string to copy.

Return Value

Type: System.String
A new string with the same value as str.

ExceptionCondition
ArgumentNullException

str is Nothing.

The following code example displays two disimilar strings referenced by two variables, creates a copy of the first string, assigns a reference to the new string to the second variable, then displays the two strings referenced by the variables to demonstrate that the strings are now identical.


' Sample for String.Copy()

Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim str1 As String = "abc"
      Dim str2 As String = "xyz"
      outputBlock.Text += String.Format("1) str1 = '{0}'", str1) & vbCrLf
      outputBlock.Text += String.Format("2) str2 = '{0}'", str2) & vbCrLf
      outputBlock.Text &= "Copy..." & vbCrLf
      str2 = [String].Copy(str1)
      outputBlock.Text += String.Format("3) str1 = '{0}'", str1) & vbCrLf
      outputBlock.Text += String.Format("4) str2 = '{0}'", str2) & vbCrLf
   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'
'


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft