我正在編寫一個腳本來取一串字母並將它們轉換爲音標值。我遇到的問題是我無法在散列表中引用值(請參閱下面的錯誤)。我不確定爲什麼代碼對我來說很好。Powershell哈希表問題
Index operation failed; the array index evaluated to null.
At C:\Scripts\test.ps1:8 char:23
+ write-host $alphabet[ <<<< $char]
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
}
參數($字符串= $(扔 '輸入字符串'))
$alphabet = @{
"A" = "Alfa";
"B" = "Bravo ";
"C" = "Charlie ";
"D" = "Delta ";
"E" = "Echo ";
"F" = "Foxtrot ";
"G" = "Golf ";
"H" = "Hotel ";
"I" = "India ";
"J" = "Juliett";
"K" = "Kilo ";
"L" = "Lima ";
"M" = "Mike ";
"N" = "November ";
"O" = "Oscar ";
"P" = "Papa ";
"Q" = "Quebec ";
"R" = "Romeo ";
"S" = "Sierra ";
"T" = "Tango ";
"U" = "Uniform ";
"V" = "Victor ";
"W" = "Whiskey ";
"X" = "X-ray";
"Y" = "Yankee ";
"Z" = "Zulu ";
}
clear-host
$charArray = $string.ToCharArray()
foreach ($char in $charArray)
{
write-host $alphabet[$char]
}
Alfa應該是Alpha ;-) – x0n 2011-04-04 21:17:24