为了账号安全,请及时绑定邮箱和手机立即绑定

检查一个字符串是否包含另一个字符串

检查一个字符串是否包含另一个字符串

蓝山帝景 2019-10-17 12:56:49
我想查找字符串中是否包含“,”(逗号)。除了逐个字符阅读之外,我们还有其他选择吗?
查看完整描述

3 回答

?
12345678_0001

TA贡献1802条经验 获得超5个赞

您也可以使用特殊词like:


Public Sub Search()

  If "My Big String with, in the middle" Like "*,*" Then

    Debug.Print ("Found ','")

  End If

End Sub


查看完整回答
反对 回复 2019-10-17
?
噜噜哒

TA贡献1784条经验 获得超7个赞

您还可以编写一个函数,如果存在子字符串,则返回TRUE,否则返回FALSE:


Public Function Contains(strBaseString As String, strSearchTerm As String) As Boolean

'Purpose: Returns TRUE if one string exists within another

On Error GoTo ErrorMessage

    Contains = InStr(strBaseString, strSearchTerm)

Exit Function

ErrorMessage:

MsgBox "The database has generated an error. Please contact the database administrator, quoting the following error message: '" & Err.Description & "'", vbCritical, "Database Error"

End

End Function


查看完整回答
反对 回复 2019-10-17
  • 3 回答
  • 0 关注
  • 621 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信