我在单元格中找到一个单词,有句子,句子&要查找的单词可能有空格/特殊字符。查找单词
但是,如果下面给出的单词退出就是例子,函数或宏应该忽略它们。
Column1 \t Column2 \t Result \t Expected Result
Spider-Man \t SpiderMan 56 \t TRUE \t TRUE
6x \t 6x25 \t TRUE \t TRUE
jesse james \t jesse/james \t TRUE \t TRUE
13.3" \t 133 hd \t FALSE \t TRUE
15.6" \t 5517 156 ccfl \t FALSE \t TRUE
United States \t United States Brands FALSE \t TRUE
United States \t UnitedStates Brands \t FALSE \t TRUE
United States \t United-States Brands FALSE \t TRUE
Force \t Air "Force" One \t FALSE \t TRUE
Force \t Air Force-One \t FALSE \t TRUE
在我下面的功能工作,但还没有得到期望的结果上面的例子。
Function ExactString(Text As String, Word As String) As Boolean
a = Module1.StripNonAlpha(Text)
b = Module1.StripNonAlpha(Word)
'ExactString = " " & UCase(a) & " " Like "*[!A-Z]" & UCase(b) & "[!A-Z]*"
If InStr(1, a, b, 1) Then
ExactString = True
Else
ExactString = False
End If
End Function
-----------------------------------------------------------------
Function StripNonAlpha(TextToReplace As String) As String
Dim ObjRegex As Object
Set ObjRegex = CreateObject("vbscript.regexp")
With ObjRegex
.Global = True
.Pattern = "[^a-zA-Z\s]+"
StripNonAlpha = .Replace(Replace(TextToReplace, "-", Chr(32)), vbNullString)
StripNonAlpha = Module1.CleanSpace(StripNonAlpha)
End With
End Function
----------------------------------------------------------------
Function CleanSpace(ByVal strIn As String) As String
strIn = Trim(strIn)
' // Replace all space pairings with single spaces
Do While InStr(strIn, " ")
strIn = Replace(strIn, " ", "")
strIn = Replace(strIn, " ", "")
Loop
CleanSpace = strIn
End Function
是否有任何其他的方式来实现我的目标?
你现在的代码有什么问题? – 2015-03-02 14:33:03
@ Gary'sStudent好心检查我的例子,我无法得到预期的结果 – Linga 2015-03-02 19:02:54