Add less than integer variable to string search

Posted by user1691832 on Stack Overflow See other posts from Stack Overflow or by user1691832
Published on 2012-10-24T15:39:56Z Indexed on 2012/10/24 17:01 UTC
Read the original article Hit count: 280

Filed under:

I'm scanning a text document for certain installed programs on a computer and looking for an easy way to include a greater or less than variable in the string I'm scanning for. Here is a very ugly and cumbersome example of what I'm using currently and while it works as a temporary fix, isn't practical or sustainable.

If CheckBox2.Checked Then
            sReader.Close()
            If text.Contains("Adobe Flash Player 11 Plugin") And
                text.Contains("Adobe Flash Player 11 ActiveX") Then
            Else
                If text.Contains("Adobe Flash Player 12 Plugin") And
                text.Contains("Adobe Flash Player 12 ActiveX") Then
                Else
                    If text.Contains("Adobe Flash Player 13 Plugin") And
                text.Contains("Adobe Flash Player 13 ActiveX") Then
                    Else

'(Goes ahead and does a silent install of the missing or outdated program)

So far I've run into this problem with both Adobe Flash and Java RTE and am certain to run into it with future programs. Essentially I need to scan for "Adobe Flash Player (Any number less than 11) Plugin" , "Adobe Flash Player (Any number less than 11) ActiveX" , "Java (number less than 9) Update (any number)".

I'm sure whatever solution is offered can likely be adapted to similar programs I'm likely to encounter later. Thanks

----- Edit -----

I've since tried the following code but it always returns the "Found" messagebox, even when no version of adobe flash is present in the file it is scanning.

If CheckBox2.Checked Then
            sReader.Close()
            Dim options As RegexOptions = RegexOptions.None
            Dim regex As Regex = New Regex("Adobe Flash Player (?<version>\d+) (Plugin|ActiveX)", options)
            Dim input As String = "Adobe Flash Player 11 Plugin"
            ' Get match
            Dim match As Match = regex.Match(input)
            Dim version As String = match.Groups("version").Value
            If (match.Success) Then
                MessageBox.Show("Version 11 or higher found, skipping install")
            Else
                MessageBox.Show("Version 11 or higher not found, installing Version 11")

© Stack Overflow or respective owner

Related posts about vb.net