gran3085
asked on
VBScript - How do I preform an operation if a part of a string is included in a longer string
I'm writing a script in VBScript and I'm writing an If/Then statment which needs to do the following:
Lets say Variable1 = "OU=sales,OU=mydomain,OU=C OM"
How do I write an If/Then statment to effectively say: "IF Variable1 contains the word "sales" THEN...
FYI, I want my script to run on all users in an OU except those in the Sales OU.
Thanks
Lets say Variable1 = "OU=sales,OU=mydomain,OU=C
How do I write an If/Then statment to effectively say: "IF Variable1 contains the word "sales" THEN...
FYI, I want my script to run on all users in an OU except those in the Sales OU.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> it's always better to have a split before compare it with the instr function..
sorry, i use a split, follow by a direct string compare, no use instr function on my example above. cheers
sorry, i use a split, follow by a direct string compare, no use instr function on my example above. cheers
understandable if there is a chance the string could contain something like:
searchfor="he"
searchstr="OU=the,OU=hello "
something like this will match "he" with instr since "the" contains he and "hello" contains he
whereas ryancys's method will return false
searchfor="he"
searchstr="OU=the,OU=hello
something like this will match "he" with instr since "the" contains he and "hello" contains he
whereas ryancys's method will return false
wow ... i guess i didn't actually look at your example very well ... i see thats what you did in your example =)
v1="inside"
v2="Check to see if inside this string"
If InStr(v2,v1)=0 Then
MsgBox "Does not exist"
Else
Msgbox "Exists"
End If