#The String class has many methods to help you work with string objects. The following table lists some of the most commonly used methods -
Sr.No | Methods and Instructions |
---|---|
1 |
public static int Compare(string strA, string strB) Compares two specified string objects and returns an integer indicating Their relative position in the sort order. |
2 | public static int Compare(string strA, string strB, boolignoreCase) strong> Compares two specified string objects and returns an integer indicating their relative position in the sort order. However, if the boolean parameter is true, case is ignored. |
3 |
public static string Concat(string str0, string str1) Connect two a string object. |
4 |
public static string Concat(string str0, string str1, string str2) Connect three string objects.
|
5 |
Public static String Concat(String str0, String str1, String str2, String str3) Connect four string objects. |
6 |
public bool Contains(string value) Returns a value indicating the specified Whether the String object appears in the string. |
7 |
public static string Copy(string str) Create a string with the specified value The same new String object string. |
8 |
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) Copy the specified number of characters from the specified position of the String object to the specified position in the Unicode character array.
|
9 |
public bool EndsWith(string value) Determine whether it is a string object The end matches the specified string. |
10 |
public bool equals(string value) Judge the current String object and the specified Whether String objects have the same value. |
11 |
public static bool Equals(string a, string b) Judge both Whether the specified String objects are the same |
Let us look at an example of using the Contains() method in C#. Contains(string value) Returns a value indicating whether the specified String object appears in this string.
using System; namespace Demo { class Program { static void Main(string[] args) { string str = "This is test"; if (str.Contains("test")) { Console.WriteLine("Yes, 'test' was found."); } Console.ReadKey() ; } } }
The above is the detailed content of C# string methods. For more information, please follow other related articles on the PHP Chinese website!