Jump to content

comparing a string


Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...