我想比较2组字符串,2个文件名,一个来自Excel范围,另一个来自SharePoint站点(不确定这是否重要)。在查看它们看起来相似的字符串时,代码并不认为如此。我们说,所有子串都可以变化。唯一的常数是" _MONTHLY DATA"和扩展" .xlsx" 。关于如何解决这个问题的任何想法?
实施例
If "2018_01_MONTHLY DATA_TOTAL_EUROPE_Germany_CompanyName Deutschland.xlsx" _
Like "2018_01_MONTHLY DATA*Europe_Germany*.xlsx" Then
MsgBox "It works"
Else
Msgbox "It doesn't work"
End If
答案 0 :(得分:1)
为了您的工作示例,您只需要:
If "2018_01_MONTHLY DATA_TOTAL_EUROPE_Germany_CompanyName Deutschland.xlsx" _
Like "2018_01_MONTHLY DATA*EUROPE_Germany*.xlsx" Then
MsgBox "It works"
Else
Msgbox "It doesn't work"
End If
如果你想让它不区分大小写,请使用Option Compare Text
:
Option Compare Text
Sub so_question()
If "2018_01_MONTHLY DATA_TOTAL_EUROPE_Germany_CompanyName Deutschland.xlsx" Like "2018_01_MONTHLY DATA*Europe_Germany*.xlsx" Then
MsgBox "It works"
Else
MsgBox "It doesn't work"
End If
End Sub