C # Learning Diary----String Type Usage summary of reference types

Source: Internet
Author: User
A basic class string is defined in C #, specifically for manipulating strings, and also for this class. NET Framework is defined in the namespace system, which is the alias of the System.String. The use of strings is extensive, and many internal operations are encapsulated in the definition of a class, and we just have to use it simply.

Create a String object:

String + object name (very simply don't say much, focus on his usage)

Examples of usages of string:

String str1 = "Welcome";             String str2 = "WELCOME";  char C = str1[0];        Returns the specified character string str3 = str1 + str2;       (+) indicates a connection between two strings can also be used with the contact (STR1,STR2) method bool B1 = (str1 = = str2);    Determine if equality int i1 = String.Compare (str1, str2); Compares two strings if the line is equal to return 0 if the STR1>STR2 return value is greater than 0 instead of less than 0 bool B2 = str3.      Contains (STR1); Whether the STR3 contains str1, returns TRUE or false string STR4 = String.    Copy (STR1); Copy string STR5 = String.  Format ("{0:f}", System.DateTime.Now); The system time format is displayed as int i2 = str2.      IndexOf (' E '); Returns the character ' E ' at the first matching position in str2 and cannot find the return-1 int i3 = str2. LastIndexOf (' E ');               Returns the index position of the last occurrence of ' E ' in str2, starting at 0. String STR6 = str1.   Insert (1, "HC");               Returns a new string where the specified string is inserted at the specified index position of the current string object. String str7 = str2.   Remove (1, 3);               Removes the specified number of characters from the specified position of the current string and returns a string. String str8 = str2.  Replace (' e ', ' e '); Removes the specified number of characters from the specified position of the current string and returns the string。 String STR9 = str2.  Replace ("com", "com");               Replaces all specified strings with another specified string and returns a new string. String str10 = str2.  ToLower ();               Converts the string to lowercase and returns. String str11 = str2.  ToUpper ();               Converts the string to uppercase and returns. String str12 = str2.  Trim ();               Removes all leading and trailing white space characters in the current String object. String str16 = String.  Concat (str1, str2, STR3, "HC666"); Connect 4 Strings of bool Str13 = str2.  Equals (STR1); Determine if equality bool Str14 = str2.   EndsWith ("COME");               Determines whether the end of a string object matches the specified string. BOOL Str15 = str2.  StartsWith ("WEL");                         Determines whether the beginning of a string instance matches the specified string.             String text = "welcome,to,hc666"; string[] Str17 = text.  Split ((', ')); Assign the text string (,) to the array str17[0]= "Welcome" str17[1]= "to" str17[2]= "HC666" string[] Joi = {"Welcome", "to", "HC6             66 "}; String str18 = String.   Join ("-", Joi); Concatenate the array through "-" into one, resulting in welcom-to-hc66

The above is what we often use, there may be some, temporarily learn so much, for each function I will not stick to the result map (too much, tired AH)

The above is the C # learning Diary----Reference type of String type usage summary, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.