#Powershell

7 messages · Page 1 of 1 (latest)

upbeat sapphire
#

Hi All,
can anyone help me understand why powershell sees the numbers in the string below as Upper case characters? the issue is it returns "Whoa, chill out!" instead of "Whatever."
<#function Get-BobResponse { param ([string] $HeyBob)

if ($HeyBob -ceq $HeyBob.ToUpper()) {
return "Whoa, chill out!"
}
else {
return "Whatever."
}
}

Get-BobResponse -HeyBob "1, 2, 3"
#>

simple sigil
#

In this code, what will the value of $HeyBob.ToUpper() be? That might help you understand why this is detected as uppercase.

upbeat sapphire
#

@simple sigil the value is “1, 2,3”

simple sigil
#

So $HeyBob and $HeyBob.ToUpper() are both "1, 2, 3"?

#

Does that explain why the code sees this string as uppercase?

upbeat sapphire
#

I see, I get it now. How can I make it to still do the same for txt strings but not for numbers?

simple sigil
#

The way I usually do it when solving in other languages is to also check if at least one letter is present