如何删除输出中的重复行?

How can I remove the repeated lines in my output?

If ArrySentence.Contains(InputString) Then
    Dim index As Integer = Array.IndexOf(ArrySentence, InputString)

    Do Until a >= ArrySentence.GetUpperBound(0) + 1
        Dim position As Integer = index + 1
        index = Array.IndexOf(ArrySentence, InputString, position)

        Console.WriteLine("The word ""{0}"" is at position {1}.", InputString, position)
        a = a + 1
    Loop

快完成了,但问题是输出重复了一些行,例如:
请输入一句话
苹果从苹果树上掉下来
apple这个词在第2位
apple这个词在第6位
apple这个词在第2位
apple这个词在第6位

求助!

我不太明白你的循环背后的原因。您要做的是: 在数组中搜索单词。如果存在,打印它的位置。否则退出。重来。

我会这样做:

Dim index As Integer = Array.IndexOf(ArrySentence, InputString)
While index >= 0 'while the word has been found
    'Output the occurrence
    Console.WriteLine("The word ""{0}"" is at position {1}.", InputString, index + 1)
    'Search for the next occurrence
    index = Array.IndexOf(ArrySentence, InputString, index + 1)
End While

试试这个,抱歉,我没有试着找出你做的那个有什么问题。

 Dim sentence as String = "The apple fall from the apple tree"
 Dim words As String() = sentence.Split(New Char() {" "c})

 For i = 0 To words.Length - 1
     If InputString = words(i) Then
          Console.WriteLine("The word ""{0}"" is at position {1}.", InputString, i + 1)
     End If
 Next