C # string manipulation

Source: Internet
Author: User

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&gt 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

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.