String.Clone Method
Returns a reference to this instance of String.
[Visual Basic] Public Overridable Function Clone() As Object Implements _ ICloneable.Clone [C#] public virtual object Clone(); [C++] public: virtual Object* Clone(); [JScript] public function Clone() : Object;
Return Value
This instance of String.
Implements
Remarks
The return value is not an independent copy of this instance; it is simply another view of the same data. Use the Copy or CopyTo method to create a separate String object with the same value as this instance.
Example
[C#, C++] The following simple code example demonstrates the Clone method.
[C#] // Create a Unicode String with 5 Greek Alpha characters String szGreekAlpha = new String('\u0319',5); // Create a Unicode String with a Greek Omega character String szGreekOmega = new String(new char [] {'\u03A9','\u03A9','\u03A9'},2,1); String szGreekLetters = String.Concat(szGreekOmega, szGreekAlpha, szGreekOmega.Clone()); // Examine the result Console.WriteLine(szGreekLetters); // The first index of Alpha int ialpha = szGreekLetters.IndexOf('\u0319'); // The last index of Omega int iomega = szGreekLetters.LastIndexOf('\u03A9'); Console.WriteLine("The Greek letter Alpha first appears at index " + ialpha + " and Omega last appears at index " + iomega + " in this String."); [C++] // Create a Unicode String with 5 Greek Alpha characters String* szGreekAlpha = new String(L'\x0319',5); // Create a Unicode String with a Greek Omega character wchar_t charArray5 [3] = {L'\x03A9',L'\x03A9',L'\x03A9'}; String* szGreekOmega = new String( charArray5 ,2,1); String* szGreekLetters = String::Concat(szGreekOmega, szGreekAlpha, szGreekOmega->Clone()); // Examine the result Console::WriteLine(szGreekLetters); // The first index of Alpha int ialpha = szGreekLetters->IndexOf(L'\x0319'); // The last index of Omega int iomega = szGreekLetters->LastIndexOf(L'\x03A9'); Console::WriteLine(String::Concat("The Greek letter Alpha first appears at index ",Convert::ToString(ialpha) )); Console::WriteLine(String::Concat(" and Omega last appears at index ", Convert::ToString(iomega), " in this String."));
[Visual Basic, JScript] No example is available for Visual Basic or JScript. To view a C# or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
String Class | String Members | System Namespace | Object | Copy | CopyTo