我試圖檢查用戶輸入的內容是否在字母數組中。然後將該字母轉換成莫爾斯碼,這是摩爾斯陣列。我必須使用char數組來按順序顯示用戶輸入,但它會按字母順序顯示莫爾斯碼。如何停止正確顯示它?提前致謝。針對不同陣列檢查字符數組vb.net
Dim strCode As String = txtCode.Text.ToUpper 'What the user enters must be letters it can also be - or =
Dim strText() As Char = strCode.ToCharArray
Dim strLetter() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
Dim strMorse() As String = {"*=", "=***", "=*=*", "=**", "*", "**=*", "==*", "****", "**", "*===", "=*=", "*=**", "==", "=*", "===", "*==*", "==*=", "*=*", "***", "=", "**=", "***=", "*==", "=**=", "=*==", "==**"}
For Each letter As Char In strText
For x As Integer = 0 To strLetter.Length - 1
If strCode.Contains(strLetter(x)) Then
MessageBox.Show(strMorse(x))
End If
Next
Next
End Sub
很好的解決方案,這正是一本字典是什麼。請注意,您在字母之間也需要空格。否則,收件人將不知道'***'是指「EEE」,「EI」,「IE」還是「S」。 – Heinzi
哦,是的,非常好的一點! – soohoonigan
@Heinzi我第二!用字典,我可以很容易地知道代碼的重點,並立即知道如何檢查翻譯,如果我覺得有需要。 –