complete-reference-vb_net_13
complete-reference-vb_net_13
Compare
The Compare method lets you compare two String object values to each other. This static method returns 0
for a match and 1 for no match, indicating the equality, or not, of the two values (see Table 15−1). The syntax
is as follows:
String.Compare(StrA, StrB)
Result: 0
You also do not always need to call an instance method because a lot of methods provided by the String class
are static. Here's an example:
In Table 15−1 the static methods are denoted with the "(s)" symbol.
This fast method can tell you whether or not you have a match of values. You can ignore the reason for the
mismatch. You can also use the CompareTo method to test for actual equality of the object's values. Table
15−2 lists the return values and their meanings for the Compare method.
n = sText.CompareOrdinal(sNewText, sTextDisplay)
CompareTo
The CompareTo method is similar to the preceding comparison method, but instead of taking two String
objects as parameters, the method compares the String parameter to the owner of the method. Consider the
following code:
497