I'm making a program that takes a sentence with no punctuation as an input, then searches for how many occurrences there are of a specific word.
Dim sntnce As String
Dim srchWord As String
Dim words As String()
Dim word As String
Dim count As Integer
Dim index As New System.Text.StringBuilder()
Console.WriteLine("Enter your sentence: ")
sntnce = Console.ReadLine()
sntnce = LCase(sntnce)
Console.WriteLine("Enter the word you want to find the position of: ")
srchWord = Console.ReadLine()
srchWord = LCase(srchWord)
words = sntnce.Split(New Char() {" "c})
Console.WriteLine(" ")
For Each word In words
If word = srchWord Then
index.Append(count)
count += 1
Else
count += 1
End If
Next
Console.WriteLine("Your word appears in the position(s)...")
Console.WriteLine(index)
Console.ReadLine()
The for loop takes the index of a word if found in a sentence and appends it to a string, but I would like to append it to an array so that the values for indexes can be outputted separately, however I can't find any solutions that help. How can I do this? Thanks
List<int>object for a variable size array.List(Of Integer)for vb.net