Visual Studio Developer Center > Visual Basic Forums > Visual Basic General > Using String.Contains with case-insensitive arguments.

Answered 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
     
     Answered

    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
     
     Answered

    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 AM
     
     
    That is exactly what I needed. Thank you very much.
  • Tuesday, May 01, 2007 12:49 PM
     
     
    What about in C#, besides uppercasing or lowercasing both the target and the source?
  • Tuesday, February 19, 2008 7:57 PM
     
     Proposed Answer

    Code Snippet

    string 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
     
     Proposed Answer

    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
    •