ProblemYou need to compare two strings without regard to their case. SolutionUse the shared Compare() method provided by the String object to compare two strings: Select Case String.Compare(content1, content2, True) Case Is < 0 MsgBox("Content1 comes before Content2.") Case Is > 0 MsgBox("Content1 comes after Content2.") Case Is = 0 MsgBox("Content1 and Content2 are the same.") End Select Setting the third parameter of the Compare() method to True instructs the method to perform a case-insensitive comparison. DiscussionThis type of string comparison compares all alphabetic characters as though lower-case and uppercase characters were identical. Figure 5-7 shows that "apples" is equal to "Apples" when the strings are compared this way. Figure 5-7. When case is ignored, lowercase and uppercase are treated identicallyString comparisons are culturally defined by default, so be sure the sort order you get is really what you want. See the Visual Studio online help for the CompareOptions property to find more information on how to make changes to the way strings are sorted. See AlsoRecipe 5.8 discusses related comparisons. |