简体   繁体   English

在Excel VBA中停用词

[英]Stop words in excel VBA

I'm working on a project in excel and I am taking a text file, reading the text file, and trying to remove the stop words from the text file. 我正在使用excel中的项目进行工作,正在获取文本文件,读取文本文件,并尝试从文本文件中删除停用词。 But I'm getting stuck on removing the stop words in excel VBA. 但是我在删除Excel VBA中的停用词时遇到了麻烦。 From the research I've seen it's possible in Java and PHP but I haven't been able to find one specifically to excel VBA. 从研究中我已经看到Java和PHP都是可行的,但是我还没有找到专门针对VBA的工具。 Is there a function that will remove stop words in excel VBA? 是否有将Excel VBA中的停用词删除的功能?

 Const InputTxtFile As String = "C:\Temp\InTxt.txt"
 Const OutputTxtFile As String = "C:\Temp\OutTxt.txt"
 Const ListOfStopWords As String = ";CAT;DOG;FOX;"

Sub main()

Dim DataLine As String
Dim strTempLine As String

Open InputTxtFile For Input As #1   'Or FreeFile()
Open OutputTxtFile For Append As #2

While Not EOF(1)
    Line Input #1, DataLine

    Dim LineTab() As String
    LineTab = Split(DataLine, " ") 'Split readed line on space

    If UBound(LineTab) > 0 Then
        For i = 0 To UBound(LineTab)
            If (InStr(ListOfStopWords, ";" + LineTab(i) + ";") = 0) Then 'Look if not in Stop Words list
                strTempLine = strTempLine + LineTab(i) + " "
            End If
        Next
        Print #2, strTempLine 'Print to output file
        strTempLine = ""
    End If

Wend

Close #1
Close #2

End Sub

'Ref: Read/Parse text file line by line in VBA '参考: 在VBA中逐行读取/解析文本文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM