Check if text is in a string

后端 未结 6 1886
北荒
北荒 2020-12-29 04:50

I want to check is some text is in a string for instance i have a string

str = \"car, bycicle, bus\"

and I have another string



        
6条回答
  •  春和景丽
    2020-12-29 05:19

    if(str.indexOf(str2) >= 0) {
       ...
    }
    

    Or if you want to go the regex route:

    if(new RegExp(str2).test(str)) {
      ...
    }
    

    However you may face issues with escaping (metacharacters) in the latter, so the first route is easier.

提交回复
热议问题