0
私はこの文を持っていると言うので、同じ項目を辞書に2回格納する必要があります: 'Hi Example Test Hi'これは1,2,3,1を出力する必要があります最初の位置を単語で保存する必要があります。ここで私が持っているコードは、これまでです:同じ項目の2つを辞書に格納する方法
If System.Text.RegularExpressions.Regex.IsMatch(userInput.Text, "^[a-zA-Z\s]+$") Then
Dim userString As String = userInput.Text 'Refers to the textbox's text.
Dim count As Integer 'Declares the count variable, which will be added to the dictionary as the word's position.
Dim d As New Dictionary(Of String, Integer) 'Declares the dictionary I will iterate through in the future.
Dim d2 As New Dictionary(Of String, Integer)
Dim wordString = userString.ToLower().Split(" "c) 'Puts the input into lower case and splits it apart by detecting each space after each word.
For Each word In wordString
If (d.ContainsKey(word)) Then
Else
d.Add(word, count) 'Adds each word to the dictionary along with the position.
count = count + 1 'Adds to the count variable to iterate through the dictionary.
End If
Next
For Each de In d
For Each dee In d2
output.Text &= de.Value + 1 & ", " & dee.Value + 1 & ", " & Environment.NewLine 'Gathers each word from the dictionary, referencing it by using 'de' and retrieving the key and value.
Next
Next
Else
MessageBox.Show("Your Sentence Is Invalid, It Must Only Contains Letters.") 'Displays a message if the sentence they inputted is invalid.
End If
おかげで、
マット
あなたの名前を付けてください。より良い変数..これは読むときには難しいですよねあなたは 'd'、' d2'、 'de'、' dee'を使います。 –
私は辞書があなたの仕事に適していないと思う、そのキー値のペアを一度格納するため、私はその数と位置を単語を格納するカスタムクラスのリストを使用することをお勧めします... – Markus