0

I want to fill the array with gussed correct letters from the solution $Solution but everytime comes the error

"Index was outside the bounds of the array"

($arrayOutput).length=$LengthSolution doesnt work

$Solution="Apfelpfannekuchen"

$arraySolution = $Solution.ToCharArray()

$LengthSolution=($Solution|measure-object -Character).Characters

$arrayOutput@()a

while ($Input -notmatch $ Solution) {

[string]$Input = Read-Host "choose a letter"

    $arrayInput = $ Input.ToCharArray()

 

    for ($i = 0; $i -lt $LengthSolution; $i++) {

        if($Input -eq $arraySolution[$i]){$arrayOutput[$i]=$Input}

        else {}

    }

    $arrayOutput

}
3
  • 4
    Please update your post and fix the syntax errors ($LengthSolution doesnt work is not a valid expression, neither is $arrayOutput@()a) Commented Feb 9, 2022 at 15:56
  • 1
    You should also NOT use $Input as self-defined variable name because it is an automatic variable
    – Theo
    Commented Feb 9, 2022 at 16:29
  • Can you check your code sample (try cutting and pasting from your question). When I run it I get… At /tmp/home/.code.tio.ps1:7 char:13 + $arrayOutput@()a + ~~ Unexpected token '@(' in expression or statement.
    – mclayton
    Commented Feb 9, 2022 at 18:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.