0

I have to check if the variables $var1, $var2, $var3 contain "172.20.110." or "172.20.111.". Is there a way to this with an IF statement (not a beautiful solution) or is there a better way to that. For Example: Can I create a "network object" with 172.20.110.0/23 (255.255.254) and check the variables against it?

1
  • 2
    We will be able to help you if you clarify your question. e. g. provide examples what $var1 looks like; what you wan't to compare with what. Commented Apr 28, 2017 at 16:23

1 Answer 1

1

The simplest solution is probably to use -match to find "172.20.110" in $var1. The -match operator returns a bool that you can check. You can figure out the if statements to compare them how you need. Check out this link for more on comparison operators that you might rather use.

$var1 = "somestuff172.20.110morestuff"
if($var1 -match "172.20.110"){"was true"}
else{"was false"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.