Vb.net 在富文本框中拆分不同的单词

Vb.net 在富文本框中拆分不同的单词,vb.net,Vb.net,我一直在尝试在富文本框中显示不同单词的数量。我已经尝试了各种方法,但仍然是一样的。请帮助。谢谢 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim FILE_NAME As String = "C:\Users\User\Desktop\FOR\testit.txt" 'read file from an existing folder in the com

我一直在尝试在富文本框中显示不同单词的数量。我已经尝试了各种方法,但仍然是一样的。请帮助。谢谢

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim FILE_NAME As String = "C:\Users\User\Desktop\FOR\testit.txt"   'read file from an existing folder in the computer
        If System.IO.File.Exists(FILE_NAME) = True Then 'check if file exists
            Dim fReader As New System.IO.StreamReader(FILE_NAME)
            RichTextBox2.Text = fReader.ReadToEnd 'read the file into the rich text box to the end
            fReader.Close()
        Else : MsgBox("No such file exists") 'if the file doesnt exist, prompt a msg box that no such file exists
        End If

        Dim newWords As String
        newWords = RichTextBox2.Text
        Dim word1 As Array
        word1 = newWords.Split(" ")
        Dim counter = 0
        Dim input As Array = word1
        Dim check As New Dictionary(Of String, String)()
        For Each p As String In input
            If Not check.ContainsKey(p) Then
                check.Add(p, 0)
                counter = counter + 1  'count distinct words in an array

            End If
            Label4.Text = counter 'display number of distinct words in label4
            check(p) += 1

        Next

你可以一直这样做:

    Label4.Text =
        RichTextBox2 _
            .Text _
            .Split(" ") _
            .ToLookup(Function(x) x) _
            .Count()

你的问题是什么/在哪里?嗯,如果我没有正确标记我的问题,我很抱歉。我是新来的。我似乎无法拆分单词。这些单词仍然连接在一起,并且需要永远计算单词。对于大多数情况,你的代码是有效的。不过,您应该小心,因为空格可能不是唯一的拆分符,换行符也可能涉及其中。在较小的样本大小上进行测试,如果仍然存在问题,请发布小样本文件的内容。你的字典应该是
(字符串,整数)
。好的,谢谢。我会改的。我已经试过了,把所有的线都拆了。这就是内容。--门被锁上了,然后我的朋友说罗瑞先生惊讶地说:“是的,德伐日先生回答得很严厉。你认为有必要让这位不幸的先生退休吗?我认为有必要把钥匙转近一点德伐日先生低声说“我不知道有什么害处,如果他的门开着,会有什么害处?”罗瑞先生喊道,“会不会有可能?”德伐日痛苦地重复了一遍