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