jsnyder213 Posted May 14, 2015 Share Posted May 14, 2015 Wondering if anyone has any suggestions.I need to create a script that compares @ComputerName to a string variable that contains "IT-"... I have looked at things such as StringSplit and trying a String Parsing... but it doesn't seem to meet what I want. (I could be doing it totally wrong)Here is some generic code of what I am trying to do.$sVariable = "IT-"If @ComputerName = $sVariable Then MsgBox(0, "Success!", "Blah Blah Blah")Else MsgBox(0, "Fail!", "Blah Blah Blah")EndIfI guess, what I am needing help on, is the "middle" piece that compares the users @ComputerName to my $sVariable? Link to comment Share on other sites More sharing options...
kylomas Posted May 14, 2015 Share Posted May 14, 2015 jsnyder213,See stringinstr() in the help file...kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 14, 2015 Moderators Share Posted May 14, 2015 As kylomas states, StringinStr() if the substring could be anywhere in the name. If it will always be IT-xxx you could also use StringLeft(). "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
jsnyder213 Posted May 14, 2015 Author Share Posted May 14, 2015 Thanks! So, if I used StringLeft I would do something like...Local $sString = StringLeft("IT-Blah, 3) essentially, anything after the IT- is of no matter, I just need to confirm that the computername starts with IT-If @ComputerName = $sString Then MsgBox(0, "Success!", "Blah Blah Blah")Else MsgBox(0, "Fail!", "Blah Blah Blah")EndIf Link to comment Share on other sites More sharing options...
iamtheky Posted May 14, 2015 Share Posted May 14, 2015 Yup, and use code tags. they are the icon to the left of the smiley. And here it is ternary.$sString = "IT-" $sResult = stringleft(@ComputerName , 3) = $sString ? "Success!" : "Fail!" msgbox(0, '' , $sResult) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
SadBunny Posted May 14, 2015 Share Posted May 14, 2015 Or use good old regex:If StringRegExp(@ComputerName, "^IT-") Then MsgBox(0, "Matches!", "Matches!") Else MsgBox(0, "Does not match!", "Does not match!") EndIf Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now