0
如何创建一个程序来识别句子中的单个单词并将它们存储在列表中?然后,我想让程序为该列表中的单词创建位置列表,将这些列表保存为单个文件。保存视觉基本单词列表
模块模块1
Sub Main()
Dim WordNumber As Integer = 0
Dim StartofWord As Integer = 1
Dim Text As String = ""
Dim L As Integer = 0
Dim Word As String
Console.WriteLine("Enter your sentence ")
Dim LotsofText As String = UCase(Console.ReadLine)
Console.WriteLine("Enter your word")
Word = UCase(Console.ReadLine())
If Mid(LotsofText, Len(LotsofText) - 1, 1) <> " " Then LotsofText = LotsofText + " "
For L = 1 To LotsofText.Length
If (Mid(LotsofText, L, 1)) = " " Then
WordNumber = WordNumber + 1
Text = (Mid(LotsofText, StartofWord, L - StartofWord))
'Console.WriteLine(Text)
StartofWord = L + 1
If Text = Word Then
Console.WriteLine(WordNumber)
End If
End If
Next
If Not Text = Word Then
Console.WriteLine("Error word not found")
End If
Console.Write("Press Enter to Exit")
Console.ReadLine()
End Sub
前端模块
想想你可能正在寻找Linq。看看http://stackoverflow.com/questions/9645326/how-to-get-distinct-values-from-listof-t-using-linq – Bugs
什么定义在你的上下文中的“单词”?如果它只是用空格分隔,你可以使用'String.Split'来获得一个单词数组 – simonalexander2005