0
我需要在字符串中查找指定單詞的位置,我需要它是非常具體的,所以它不包含沒有空格的單詞,所以說如果我是尋找單詞'嗨'它只會返回true,如果它是檢查'嗨'而不是'HiExample'。在另一個字符串中查找指定字符串的位置
代碼:正如我已經轉換的串入下殼體
Dim userString As String = userInput.Text
userString = userString.ToLower()
Dim d As New Dictionary(Of String, Integer)
Dim wordString = userString.ToLower().Split(" "c)
Dim iList As New List(Of String)()
For Each word In wordString
If d.ContainsKey(word) Then
d(word) += 1
iList.Add(word)
Else
d.Add(word, 1)
End If
Next
For Each de In d
For i As Integer = 0 To wordString.Count - 1
Dim index As Integer = userString.IndexOf(de.Key)
output.Text &= "Word: " & de.Key & " Occurrence: " & de.Value & " Position: " & GET POSTION OF EACH WORD HERE & Environment.NewLine
Next
Next
檢查大寫或小寫將不是必需的。
感謝,
馬特
你瞭解正則表達式?這裏可能有用 – ADyson