I would like to check a data in my file exist or not in an array data that I have. It will return 1 and 0 if its exit or not. Inside my file is like this:
2j2H4F6d9d0d3hdfasgt.y7
But I cut the last 2 lines. And my array data is like this: [2w fr 5k 2j 0w]. I want to check whether my array data exist inside my file.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
XX = 0
Set wshShell = CreateObject("WScript.Shell")
strFBString = wshShell.ExpandEnvironmentStrings("%FB%")
WScript.Echo "==>"
WScript.Echo "strFBString: " & strFBString
Set wshShell = Nothing
For i = 1 To Len(strFBString) Step 2
If StrComp(Mid(strFBString, i, 2), [2w fr 5k 2j 0w]) = 0 Then
XX = 1
End If
Next
WScript.Echo "XX: " & XX
WScript.Quit(XX)
For one thing,
[2w fr 5k 2j 0w]
is not a valid array definition in VBScript. If you want to define an array with these 5 string elements you need to do it like this:Also,
StrComp()
is for comparing a string to another string. It does not support comparing a string to an array. For comparing a string to each element of an array you need a loop. How to build that loop depends on the result you want to achieve, though.Looking at your code it seems you want to find a match in
2j2H4...
, but not inw2j2H...
, so simply usingInStr()
probably won't work for you. In that case you could use an inner loop for the comparison:But like I already said, details depend on the desired end result. If you want to check if your input string contains any of the array values you could do something like this:
If on the other hand you wanted to check if your input string contains all of the reference strings you'd probably do something like this instead:
You could also use an entirely different approach, like putting your data in a dictionary:
Using that approach you could check if the data contains any of the reference values like this:
or check if the data contains all of the reference values like this: