简体   繁体   中英

If condition is driving me crazy

Please I need help... two identical strings are not returning $True when checking on IF logical statement.

The images illustrates perfectly my frustration. I'm starting with GUIs don't be cruel please.

I've tried checking with label text with variables from textbox.text everything that came to my mind...

blob: https://imgur.com/5fcdabfb-b86e-436d-9c57-ed5f97c48229


        Write-Host "$Udrive\$($comboSamaccount.Text)"
        Write-Host "$Homedirectory"
        $Udriveinfo = "$Udrive\$($comboSamaccount.Text)"
        $labeUdriveINFO.Text = $Udriveinfo
        $labeUdriveINFO.Text -eq "$Homedirectory"
        if ("$Udrive\$($comboSamaccount.Text)" -eq "$Homedirectory")
        {
            $Ud = "The U drive is - OK"
        }
        else
        {
            $Ud = "The U drive must be changed to $Udrive\$($comboSamaccount.Text)"
        }
    }

Thanks in advance.

Best regards.

For the purposes of troubleshooting this, I'd do the following:

$a = "$Udrive\$($comboSamaccount.Text)"
$b = "$Homedirectory"
for($i = 0; $i -lt $a.Length; $i++)
{
  if("$($a[$i])" -ne "$($b[$i])"){
    Write-Host 'Mismatch found' -ForegroundColor Red
    Write-Host ('[{4:D2}] {0}:{1:X} - {2}:{3:X}' -f $a[$i],(+$a[$i]),$b[$i],(+$b[$i]),$i)
  }
}

This will go through the characters in the strings one by one and try to find the ones that aren't the same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM