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

我想查找字符串中是否包含“,”(逗号)。除了逐个字符阅读之外,我们还有其他选择吗?



蓝山帝景
浏览 628回答 3
3回答

12345678_0001

您也可以使用特殊词like:Public Sub Search()  If "My Big String with, in the middle" Like "*,*" Then    Debug.Print ("Found ','")  End IfEnd Sub

噜噜哒

您还可以编写一个函数,如果存在子字符串,则返回TRUE,否则返回FALSE:Public Function Contains(strBaseString As String, strSearchTerm As String) As Boolean'Purpose: Returns TRUE if one string exists within anotherOn Error GoTo ErrorMessage    Contains = InStr(strBaseString, strSearchTerm)Exit FunctionErrorMessage:MsgBox "The database has generated an error. Please contact the database administrator, quoting the following error message: '" & Err.Description & "'", vbCritical, "Database Error"EndEnd Function
打开App,查看更多内容
随时随地看视频慕课网APP