我在單元格中找到一個單詞,有句子,句子&要查找的單詞可能有空格/特殊字符。查找單詞
但是,如果下面給出的單詞退出就是例子,函數或宏應該忽略它們。
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