String class-copying copy () and CopyTo ()

Source: Internet
Author: User

1, copy ();

"Syntax":

public static string Copy (String str);
Parameter--str the string to copy
Return value--a new string with the same value as Str
//Sample for string.copy ()usingSystem;classSample { Public Static voidMain () {stringSTR1 ="ABC"; stringSTR2 ="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 '*/

2, CopyTo ();

"Syntax":

public void CopyTo (int sourceIndex, //is the starting position of the character to be copied char[] destination, //for the target character array int Destinatio NIndex, //Specifies the starting position in the destination array int count //Specifies the number of characters to copy. )
stringStrsource ="changed";Char[] Destination = {'T','h','e',' ','I','N','I','T','I','a','L',' ','a','R','R','a','y' }; Console.WriteLine (destination);//Result: The initial arrayStrsource.copyto (0, Destination,4, strsource.length); Console.WriteLine (destination);//Result: the changed arraystrsource="A Different string"; Strsource.copyto (2, Destination,3,9); Console.WriteLine (destination);//results: ThedifferentarrayConsole.readkey ();

String class-copying copy () and CopyTo ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.