C # Learning diary 15 ---- string type Reference Usage Summary

Source: Internet
Author: User

C # Learning diary 15 ---- string type Reference Usage Summary

 

C # defines a basic class string for string operations. This class is also used. the namespace defined in System of the Net Framework Structure is System. the alias of string. The use of strings is very extensive, and many internal operations are encapsulated in the definition of classes. We only need to make simple use of them.

Create a string object:

String + Object Name (this is easy to describe and focuses on its usage)

 

String usage example:

 

String str1 = welcome; string str2 = WELCOME; char c = str1 [0]; // return the specified string str3 = str1 + str2; // (+) it indicates that two strings can be connected. You can also use the Contact (str1, str2) method bool b1 = (str1 = str2); // you can determine whether it is equal to int i1 = string. compare (str1, str2); // Compare the two strings to see if they are equal, return 0 if they are equal. If str1> str2 returns a value greater than 0, return a value less than 0 bool b2 = str3.Contains (str1 ); // If str3 contains str1, true or false is returned. string str4 = string. copy (str1); // Copy string str5 = string. format ({0: f}, System. dat ETime. now); // format the system time to display int i2 = str2.IndexOf ('E'); // return the first matched position of the character 'E' in str2, -1 int i3 = str2.LastIndexOf ('E') cannot be found; // The last index position of 'E' in str2. the index starts from 0. String str6 = str1.Insert (1, HC); // returns a new string, where the specified string is inserted at the specified index location of the current string object. String str7 = str2.Remove (1, 3); // removes a specified number of characters from the specified position of the current string and returns the string. String str8 = str2.Replace ('E', 'E'); // removes a specified number of characters from the specified position of the current string and returns the string. String str9 = str2.Replace (COM, com); // replace all specified strings with another specified string and return a new string. String str10 = str2.ToLower (); // converts a string to lowercase and returns it. String str11 = str2.ToUpper (); // converts a string to uppercase and returns the result. String str12 = str2.Trim (); // removes all leading and trailing spaces from the current String object. String str16 = string. concat (str1, str2, str3, HC666); // connect four strings bool str13 = str2.Equals (str1); // determine whether the two strings are equal bool str14 = str2.EndsWith (COME ); // determine whether the end of the string object matches the specified string. Bool str15 = str2.StartsWith (WEL); // checks whether the start of the string instance matches the specified string. String text = welcome, to, HC666; string [] str17 = text. split (','); // convert the text string (,) allocated to the array str17 [0] = welcome str17 [1] = to str17 [2] = HC666 string [] joi = {welcome, to, HC666}; string str18 = string. join (-, joi); // concatenate an array through "-", and the result welcom-to-HC66


The above are frequently used, and there may be others. I have learned so much for the moment, and I will not stick the result graph for every function (too much, tired)

 

 

 

 

 

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.