Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

-Match and $Matches[0] in a single if?

$
0
0

This bit of code seems to be working intermittently for me, and I can't nail down what the problem is.

if (($Places[-1] -match "([0-9])") -and ([bool]($Matches[0] -as [int]))) {
some stuff
}

If I make it two different if's it always works, but for the life of me I don't know why this -and version isn't working all the time. I may also be testing excessive conditions, as there really should never be a decimal number there to find, but it seems like this should still work all the time, given a single one or two digit number to be found in the string.

Thoughts?

Gordon


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>