Using String.Contains with case-insensitive arguments.
-
Friday, December 08, 2006 1:02 AM
Is there any way to use
Dim Str as String = "UPPERlower"
Str.Contains("UpperLower") and have it return true?
Answers
-
Friday, December 08, 2006 1:13 AM
The following will return true
Option Compare Text
Public Class Form1
Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Str As String = "UPPERlower"
Dim b As Boolean = InStr(Str, "UpperLower")
End Sub
End Class
All Replies
-
Friday, December 08, 2006 1:13 AM
The following will return true
Option Compare Text
Public Class Form1
Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Str As String = "UPPERlower"
Dim b As Boolean = InStr(Str, "UpperLower")
End Sub
End Class -
Friday, December 08, 2006 2:11 AMThat is exactly what I needed. Thank you very much.
-
Tuesday, May 01, 2007 12:49 PMWhat about in C#, besides uppercasing or lowercasing both the target and the source?
-
Tuesday, February 19, 2008 7:57 PM
Code Snippetstring target = "mello yello";
string find = "Lo";
if (0 <= target.IndexOf(find, StringComparison.InvariantCultureIgnoreCase)) {
// found
}
else {
// not found
}
- Proposed As Answer by Piyush Shah Friday, October 24, 2008 8:14 PM
-
Monday, May 31, 2010 12:06 PM
The method I always use is the following (c#):
Str.ToUpperInvariant().Contains("UpperLower".ToUpperInvariant());
- Proposed As Answer by Damden Monday, May 31, 2010 12:06 PM

