Я пишу сценарий, чтобы взять строку букв и преобразовать их в фонетические значения.У меня проблема в том, что я не могу ссылаться на значение в хеш-таблице (см. Ошибку ниже).Я не уверен, почему, поскольку код выглядит нормально для меня.
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
}
param ($ string = $ (throw 'Enter a string')))
$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]
}