如何使用vbscript查找在单行内匹配的两个文本?例如:
This UserName is Logged on already.
如何搜索“用户名”和“已登录”?
答案 0 :(得分:3)
在这种情况下,正则表达式可能有点过分。我建议使用InStr()
进行此类检查:
s = "This UserName is Logged on already."
If InStr(s, "UserName") > 0 And InStr(s, "Logged on") > 0 Then
'...
End If
如果要使检查更具可读性,可以将InStr()
包装在辅助函数中:
s = "This UserName is Logged on already."
If Contains(s, "UserName") And Contains(s, "Logged on") Then
'...
End If
Function Contains(str1, str2)
Contains = False
If InStr(str1, str2) > 0 Then Contains = True
End Function