如何在字符串比较中忽略大小写
How to ignore case in string comparison
我有一个ExcelVBA公式:-
If [G56] = "Not Applicable" Then
...
区分大小写。我希望它忽略 "Not applicable".
的大小写
您可以只使用 LCase 函数:
If LCase([G56]) = "not applicable" Then
或在模块顶部添加Option Compare Text
:
Option Explicit
Option Compare Text
Sub Test()
MsgBox "Not Applicable" = "Not applicable" 'True
End Sub
你也可以使用比较字符串的专用函数:
Dim result As Integer
'// vbTextCompare does a case-insensitive comparison
result = StrComp("Not Applicable", "NOT APPLICABLE", vbTextCompare)
If result = 0 Then
'// text matches
End If
中有一些关于 StrCompare
方法的更多信息
最快的选择是
StrComp(LCase$("Not Applicable"), "not applicable", vbBinaryCompare)
我有一个ExcelVBA公式:-
If [G56] = "Not Applicable" Then
...
区分大小写。我希望它忽略 "Not applicable".
的大小写您可以只使用 LCase 函数:
If LCase([G56]) = "not applicable" Then
或在模块顶部添加Option Compare Text
:
Option Explicit
Option Compare Text
Sub Test()
MsgBox "Not Applicable" = "Not applicable" 'True
End Sub
你也可以使用比较字符串的专用函数:
Dim result As Integer
'// vbTextCompare does a case-insensitive comparison
result = StrComp("Not Applicable", "NOT APPLICABLE", vbTextCompare)
If result = 0 Then
'// text matches
End If
中有一些关于 StrCompare
方法的更多信息
最快的选择是
StrComp(LCase$("Not Applicable"), "not applicable", vbBinaryCompare)