C # Basics of string article

Source: Internet
Author: User

Once I have seen many colleagues write classes similar to the Stringhelper class (which encapsulates some common string manipulation methods), I have written similar classes, encapsulating strings, comparing strings, judging strings, and other commonly used string manipulation methods. Now that most of these methods are redundant, Microsoft has provided many common operations for strings and is more powerful and easier to use than it writes. Some common methods are listed below:

String input = ", ABCDE,";
String[] Inputs = {"A", "B", "C", "D"};

//Remove the Spaces
Console.WriteLine ("\" + input) before the string. TrimStart () + "\" ");

//Remove the specified character before the string
Console.WriteLine ("\" + input. TrimStart (', ', ') + "" ");

//Remove the Spaces
Console.WriteLine ("\" + input) after the string. TrimEnd () + "\" ");

//Remove the specified character after the string
Console.WriteLine ("\" + input. TrimEnd (', ', ') + "" ");

//Remove the Spaces
Console.WriteLine ("\" + input) before and after the string. Trim ());

//Remove the specified character before and after the string
Console.WriteLine ("\" + input. Trim (', ', ') + "" ");

//Inserts the string
Console.WriteLine (input) at the specified position of the string. Insert (0, "ABCDE"));

//Stitching string array
Console.WriteLine (String.Concat (inputs));

//concatenation of the string array with the specified delimiter
Console.WriteLine (String.Join (",", inputs));

//Use the specified delimiter to stitch the string array and specify the location
Console.WriteLine (String.Join (",", inputs, 0, 2));

//Compare two strings
Console.WriteLine (String.Compare ("abc", "abc");

//Compares two strings and ignores case
Console.WriteLine (string.comparE ("ABC", "abc", true);

Although the above methods are not of any technical content, they are very helpful to us in the process of development. In software development, technology is certainly necessary, but the foundation is very important, careful is important, quality is very important.

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.