我在填充 char 数组中的空数组元素时遇到问题。
我有一个inputArray,它将我为myInput键入的所有字符存储到一个数组中。然后我创建了一个charArray,它将从inputArray中获取字符,然后如果它在数组中没有遇到任何内容,我想添加 -1 以表示我的charArray中的空位置。我没能做到这一点。我输入“你好”,它会输出给我
H
E
L
L
O
Space
Space
Space
Space
And So On, until I reach the end of that array.
*"Space" is for visual aid of output
我迷路了。我希望能够过滤掉“-1”,而不是计算构成单词所需的下划线数量,例如“Hello”将是 _ _ _ _ _ (省略带有“-1”的元素或里面什么都没有。)
Module GuessingGame
Sub Main()
Dim myInput As String.
Dim inputArray(11) As Char
Dim charArray(11) As Char
Dim myLetter As String
Dim attempts As Integer = 0
Dim incorrectAttempts As Integer = 0
Dim remainingAttempts As Integer = 0
myInput = InputBox$("Please enter a word or phrase: ")
inputArray = myInput.ToCharArray()
While inputArray.Length > 12
System.Console.WriteLine("Error: The word or phrase needs to be 12 characters or less")
myInput = InputBox$("Please enter a word or phrase: ")
inputArray = myInput.ToCharArray()
End While
For i = 0 to inputArray.length - 1
If IsNothing(inputArray(i)) Then
charArray(i) = "-1"
Else
charArray(i) = inputArray(i)
End If
Next
Console.Clear()
For Each element In charArray
System.Console.WriteLine(element)
Next element
For i = 0 to inputArray.length - 1
remainingAttempts = remainingAttempts + 1
Next
remainingAttempts = remainingAttempts - 1
System.Console.WriteLine("Guessing Game Display")
System.Console.WriteLine("---------------------")
System.Console.WriteLine("Number of Remaining Attempts: " & remainingAttempts)
System.Console.WriteLine("Number of Incorrect Attempts: " & incorrectAttempts)
System.Console.WriteLine("Number of Attempts: " & attempts)
System.Console.WriteLine("Guess a Character? ")
myLetter = InputBox$("Please enter a character: ")
End Sub
End Module