C # String

Source: Internet
Author: User

The string class represents a sequence of characters (0 or more Unicode characters), and string is the alias string str;//declaration for string in the. NET Framework String

1             stringStr//declaring a string2str ="Hello world!";//Assigning a value to a string3             stringstr ="";//empty string4             stringStr=string.empty;//empty string, read only;5             CharCh=str. chars[0];//gets the 1th character of a string str;6             intI=str. Length;//Get string length7String.contact ("A","B");//Connection String8Str. Contains ("ABC");//returns whether the character contains the string ABC9Str. EndsWith ("ABC");//returns whether the character ends with the string ABCTenString.Format ("This is a {0} statement;", str);//Formatting Strings OneStr. IndexOf ('A');//returns the first index of character a in the string str AStr. LastIndexOf ('A');//returns the last index of the character a in the string str -Str. Insert (0,"ABC");//inserting ABC at position 0 of the string str -Str. PadLeft (Ten,'A');//Add the character A to the left of the string Str so that its total length reaches ten theStr. PadRight (Ten,'A');//Add the character A to the right of the string str so that its total length reaches ten -Str. Remove (2);//removes 2 characters from the string str; -Str. Replace ('A','B');//use B instead of a in a string -             Char[] ch = str. ToCharArray ();//converting a string str to a character array +Str. ToLower ();//Convert str to lowercase letters -Str. ToUpper ();//Convert str to uppercase letters +Str. Trim ();//Remove the space from Str AStr. TrimStart ();//remove the starting whitespace character from Str atStr. TrimEnd ();//remove the trailing white character from Str

C # String

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.