VBA判断在指定字符串中是否有指定字符

比如在“张三家里有条狗名字叫小花”字符串中判断是否有“名字”存在?

 

 

Sub test1()
    Dim str As String
    str = "张三家里有条狗名字叫小花"
    If InStr(str, "名字") Then
        MsgBox "包含"
    Else
        MsgBox "不包含"
    End If
End Sub



Sub test2()
    Dim str As String
    str = "张三家里有条狗名字叫小花"
    If str Like "*名字*" Then
        MsgBox "包含"
    Else
        MsgBox "不包含"
    End If

 End Sub

  

 

  

 

posted on 2021-07-31 10:42  这个名字不好用  阅读(4537)  评论(0编辑  收藏  举报

导航