Common method summarization for String classes in C

  • 2020-12-07 04:12:11
  • OfStack

An example of this article summarizes common String class methods in C#. Share to everybody for everybody reference. The specific analysis is as follows:

The String class in C# is very useful. Here is a summary of some of its common methods. If you use these flexibly, the String class will be pretty good.

.ToLower () // converted to lowercase string "AbC"-- > "abc"
.ES15en () // Change to capital letters "AbC" -- > "ABC"
.Trim () // Remove the space at the beginning and end of the string "abc "-- > "abc"
.Equals(string value,StringComparison comparisonType); // Equality judgment
//StringComparison.CurrentCulture
//StringComparison.CurrentCultureIgnoreCase
//StringComparison.InvariantCulture
//StringComparison.InvariantCultureIgnoreCase
//StringComparison.Ordinal
//StringComparison.OrdinalIgnoreCase

.ES44en (string value) // Size compared to value

.Split (params char [] separator) //separator are separator characters such as: ',',' |', and so on.
.Split(char [] separator ,StringSplitOptions splitOpt)//StringSplitOptions.RemoveEmptyEntries
.Split (string[] separator,StringSplitOptions splitOpt)// separated by string

.Replace (char oldChar,char newChar) // replaces a character in a string such as 'a' with 'b'
.Replace (string oldStr,string newStr)// Replace the string in the string, e.g. "Li Shizhen" with "Li Xiuli"

.SubString (int startIndex) // Consists of a string starting with the specified ordinal number,1 up to the end
.SubString (int startIndex,int length) // Take length in succession from the specified serial number startIndex, exceeding the length will report an exception

.Contains (char c) // Whether contains characters or not
.Contains (string str) // whether contains substrings

StartsWith (string str)/whether/begin with str, such as: http: / / baidu com on http: / / at the beginning
.EndsWith (string str) // Whether to end with str

.IndexOf (char c) // Find index for first character c, return -1 if not found
.IndexOf (string str) // Find the location of the first string str

Hopefully this article has helped you with your C# programming.


Related articles: