The return values of this method are identical to the values returned by the String.Compare method in the previous table. The String.CompareTo method compares the string that the current string object encapsulates to another string or object. This example displays -32 to the console. String^ string1 = "Hello World!" Ĭonsole::WriteLine(String::CompareOrdinal(string1, "hello world!")) Ĭonsole.WriteLine(String.CompareOrdinal(string1, "hello world!")) Ĭonsole.WriteLine(String.CompareOrdinal(string1, "hello world!")) The following example uses the CompareOrdinal method to compare the values of two strings. Instead, to determine whether two strings are equal, use the String.Equals(String, String, StringComparison) method. You should not use the String.CompareOrdinal method to test for equality (that is, to explicitly look for a return value of 0 with no regard for whether one string is less than or greater than the other). The String.CompareOrdinal method is primarily intended for use when ordering or sorting strings. The return values of this method are identical to the values returned by the Compare method in the previous table. The String.CompareOrdinal method compares two string objects without considering the local culture. For an example that demonstrates how to use the String.Compare method to perform a culture-insensitive comparison, see Culture-insensitive string comparisons. To perform a culture-insensitive string comparison, use an overload of the String.Compare method that allows you to specify the culture to use by supplying a culture parameter. The preceding example is culture-sensitive by default. String^ string1 = "Hello World!" Ĭonsole::WriteLine(String::Compare(string1, "Hello World?")) Ĭonsole.WriteLine(String.Compare(string1, "Hello World?")) Ĭonsole.WriteLine(String.Compare(string1, "Hello World?")) The following example uses the String.Compare method to determine the relative values of two strings. You should not use the String.Compare method to test for equality (that is, to explicitly look for a return value of 0 with no regard for whether one string is less than or greater than the other). The String.Compare method is primarily intended for use when ordering or sorting strings. The first string follows the second string in the sort order. The first string and the second string are equal. The first string precedes the second string in the sort order. The following table shows the three integer values that this method might return. Additionally, overloads are provided that regard or disregard case and cultural variance. You can use this function to compare two strings or substrings of two strings. The static String.Compare method provides a thorough way of comparing two strings. Returns the index position of a character or string, starting from the end of the string you are examining. Returns the index position of a character or string, starting from the beginning of the string you are examining. Returns a Boolean value.ĭetermines whether two strings are the same. Returns a Boolean value.ĭetermines whether a character or string occurs within another string. Returns a Boolean value.ĭetermines whether a string ends with the string passed. Returns an integer value.ĭetermines whether a string begins with the string passed. Returns an integer value.Ĭompares the current string object to another string. Returns an integer value.Ĭompares two strings without regard to local culture. Method nameĬompares the values of two strings. The following table lists and describes the value-comparison methods. NET provides several methods to compare the values of strings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |