Sign in to follow this  
Followers 0

Stringsplit - Testing Multi Substrings?

2 posts in this topic


I have a question about the use of StringSplit, and perhaps its a matter of syntax. The following code is a snippet of the code I'm working on to update all hotfixes on a given PC. This code test the version of Windows Media Player installed (in this case I'm focusing on WMP for XP).

$WMPInstalled = RegRead ( 'HKEY_LOCAL_MACHINE\' & 'Software\Microsoft\Active Setup\Installed Components\{6BF52A52-394A-11d3-B153-00C04F79FAA6}', 'IsInstalled' )
    If $WMPInstalled = '1' Then
$WMPVer = RegRead ( 'HKEY_LOCAL_MACHINE\' & 'Software\Microsoft\Active Setup\Installed Components\{6BF52A52-394A-11d3-B153-00C04F79FAA6}', 'Version' )
$WMPVer = StringReplace($WMPVer, ",", ".")
    MsgBox(0, "Windows Media Player", $WMPVer)
$WMPVer = StringSplit($WMPVer, ".")
If $WMPVer[4] = "4487" Then
    MsgBox(0, "String Data", "WMP is version 8")

I understand how to check for a specific substring, in the example above the 4th substring. But is there a way to check, in a single statement, multiple substrings? Say the first, second, & third as a group? Such as StringSplit [1][2][3] or must I work through each substring and branch accordingly? i.e. check and see if the version is 8.0.0 at a single check or do I test StringSplit [1] to see if it is 8, if so check StringSplit [2] to see if it is 0, etc.

Perhaps a better example might be trying to test the first 3 octets of an IP address where I'm not concerned about the 4th octet but need to match the computers IP to a list of IP's.

Would appreciate anyone's thoughts on this.


Share this post

Link to post
Share on other sites

Is this the idea you're going for?

Using the IP because it's simpler...

$ip = "100.200.300.400" ; Of course that's not valid, shhh

$a = StringSplit($ip, ".")
; Should error check here...
If $a[1] >= 100 AND $a[2] < 201 AND $a[3] = 300 Then MsgBox(4096, "Good", "Good")

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0