Jump to content
jsnyder213

comparing a string

Recommended Posts

jsnyder213

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")
EndIf

I guess, what I am needing help on, is the "middle" piece that compares the users @ComputerName to my $sVariable?

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
JLogan3o13

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().


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jsnyder213

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

Share this post


Link to post
Share on other sites
iamtheky

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)

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
SadBunny

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.

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

×