我正在用excel做一个项目,我正在获取一个文本文件,读取文本文件,并尝试从文本文件中删除停用词。但我一直坚持删除 excel VBA 中的停用词。从研究中我看到它在 Java 和 PHP 中是可能的,但我无法找到一个专门用于擅长 VBA 的。是否有可以删除excel VBA中的停用词的功能?
问问题
1548 次
1 回答
0
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
于 2015-04-10T14:59:06.127 回答