美文网首页
判断字符串是否包含某个字符串

判断字符串是否包含某个字符串

作者: kafya | 来源:发表于2020-07-16 17:52 被阅读0次

    String对象 方法

    一:indexOf()

    "12345".indexOf("3")> -1? true: false;
    

    二:search()

    "123".search("3")>-1? true : false;
    

    三:march()

    "123".match(/3/) ? true: false;
    

    RegExp对象方法

    四:test()

    RegExp(/3/).test("123") ? true: false;
    

    五:exec()

    RegExp(/3/).exec("123123") ? true :  false;
    

    相关文章

      网友评论

          本文标题:判断字符串是否包含某个字符串

          本文链接:https://www.haomeiwen.com/subject/tplmhktx.html