如何从指定的数组/列表中查找缺失的单词?
我有一个需要验证的单词列表是否包含在数百个文档中。
我想出了如何从文档中找到的列表中突出显示/着色单词(下面的代码)。
我需要知道缺少哪些单词。
Sub HighlightWords()
Dim vWords As Variant
Dim sWord As Variant
vWords = Array("SQL query", "Selenium", "Cucumber", "Rest-Assured", "Rest assured", "REST API", "TestNG", "SVN", "Subversion", "Maven", "IntelliJ", "Ecliipse", "Confluence", "JIRA", "Sauce Labs", "GitLab", "HTML", "XPATH", "CSS", "Object Oriented Programming", "Object-Orienting Programming", "OOP")
For Each sWord In vWords
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = wdYellow
With Selection.Find
.Text = sWord
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next sWord
End Sub
I have a list of words I need to verify are included in hundreds of documents.
I figured out how to highlight/color words from the list which are found within the document (code below).
I need to know which words are missing.
Sub HighlightWords()
Dim vWords As Variant
Dim sWord As Variant
vWords = Array("SQL query", "Selenium", "Cucumber", "Rest-Assured", "Rest assured", "REST API", "TestNG", "SVN", "Subversion", "Maven", "IntelliJ", "Ecliipse", "Confluence", "JIRA", "Sauce Labs", "GitLab", "HTML", "XPATH", "CSS", "Object Oriented Programming", "Object-Orienting Programming", "OOP")
For Each sWord In vWords
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = wdYellow
With Selection.Find
.Text = sWord
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next sWord
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码将在消息框中显示缺少的术语。
The following code will display the missing terms in a message box.
下面将为您提供缺失单词作为集合或数组的列表:
请注意,将文档中关键字是否存在的测试外包到函数中可以使您的代码更具可读性,并且更容易测试或重用。
The following will give you a list of the missing words as collection or array:
Note that outsourcing the test if a keyword is in the document into a function makes your code more readable and it is easier to test or re-use.