Question

Is there an easy way to do this comparision with ignorecase ON?

If file.Extension = ".Lnk" Then MsgBox(file.Extension)

What i'm trying to do is to get all the ".lnk" or ".LNK" or ".lNk" or " ".Lnk" etc...

I know this is possibly with RegEx but... there's an easy way for that example?

Thankyou for read

Was it helpful?

Solution

Convert the extension to lowercase using ToLower and then compare

If file.Extension.ToLower = ".lnk" Then MsgBox(file.Extension)

And forget Regex for this. It's really overkill and inappropriate

OTHER TIPS

Use String.Equals for string comparisons. To ignore case use CurrentCultureIgnoreCase or InvariantCultureIgnoreCase.

If String.Equals("AAA", "aaa", StringComparison.InvariantCultureIgnoreCase) Then

    'more code

End If

MSDN: String.Equals Method (String)

MSDN: Specifying String Comparisons Explicitly

use this for ignore case compare

If String.Compare(file.Extension, ".lnk", True) = 0 Then MsgBox(file.Extension)

change true to false for case sensitive compare

Module Test

Sub Main()
    Dim userString As String = Nothing
    Dim finalString As String = "Jacob"

    Console.WriteLine("Enter username")
    userString = Console.ReadLine()

    If String.Compare(finalString, userString, True) = 0 Then
        Console.WriteLine("Access Granted")
    Else
        Console.WriteLine("Access Denied")
    End If


    Console.ReadLine()

End Sub

End Module

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top