One, string manipulation//String to array string mystring= "This is a string" char[] mychars=mystring. ToCharArray ();//foreach loop processing char array foreach (char mychar in mystring) {Console.WriteLine (MyChar);} MyString. Length//Get the number of elements two, turn the case <string>. ToLower ()//lowercase <string>. ToUpper ()//uppercase Three, remove spaces in the string or other characters <string>. Trim ()//clear whitespace in string <string>. TrimStart ()//clears the space before the string <string>. TrimEnd ()//Clears the space after the string char[] trimchars ={', ' e ', ' s '};mystring. Trim (trimchars); Clears the space in MyString, E, s character Fu Shi, adds a space to the string, or <string> the specified character;. PadLeft (); Add a space to the left <string>. PadRight (); Add a space mystring=mystring to the right. PadLeft (10); Causes the string to reach the specified length (10) and adds a space mystring=mystring before it is reached. PadLeft (10, '-'); Causes the string to reach the specified length (10), if it is not up to the front to add the '-' word Fu, the split character <string> Split (); string mystring= "This is a test."; Char[] separator={'}; Space string[] mywords=mystring. Split (separator); Use separator (spaces) to split the string Mystringforeach (string Word in mywords)//Use foreach to iterate over the Mywords array {console. WriteLine ("{0}", Word);}
C # string manipulation