我期待$ Flag_CreditTrend为1.但它等于0。 有什么想法吗?
$Note = "test, up"
$CreditScoreTrend = ($Note -split ',')[1].trim()
$Flag_CreditTrend = 0
$CreditScoreTrend
if ($CredScoretrend -match 'up') {$Flag_CreditTrend = 1}
#if ($CredScoretrend -like 'up') {$Flag_CreditTrend = 1}
#if ($CredScoretrend -eq 'up') {$Flag_CreditTrend = 1}
$Flag_CreditTrend
答案 0 :(得分:1)
看看你写的是什么:
$Note = "test, up"
$CreditScoreTrend = ($Note -split ',')[1].trim()
$Flag_CreditTrend = 0
$CreditScoreTrend
if ($CredScoretrend -match 'up') {$Flag_CreditTrend = 1}
#if ($CredScoretrend -like 'up') {$Flag_CreditTrend = 1}
#if ($CredScoretrend -eq 'up') {$Flag_CreditTrend = 1}
$Flag_CreditTrend
第5行if ($CredScoretrend -match 'up') {$Flag_CreditTrend = 1}
使用变量$CredScoretrend
而不是您想要的变量$CreditScoreTrend
。由于此新变量未分配,因此不匹配' up'如你所料。这将返回false,因此永远不会将Flag_CreditTrend
指定为1.因此,$Flag_CreditTrend
将返回您在第3行分配的值0。
答案 1 :(得分:0)
变量参考错误,请查看注释行
$Note = "test, up"
$CreditScoreTrend = ($Note -split ',')[1].trim()
$Flag_CreditTrend = 0
$CreditScoreTrend
if ($CreditScoreTrend -match 'up') {$Flag_CreditTrend = 1}#here CreditScoreTrend is to be used
#if ($CredScoretrend -like 'up') {$Flag_CreditTrend = 1}
#if ($CredScoretrend -eq 'up') {$Flag_CreditTrend = 1}
$Flag_CreditTrend