javascript - Check if text is in a string -



javascript - Check if text is in a string -

i want check text in string instance have string

str = "car, bycicle, bus"

and have string

str2 = "car"

i want check if str2 in str.

i newbie in javascript please bear me :)

regards

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

or if want go regex route:

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

however may face issues escaping (metacharacters) in latter, first route easier.

javascript

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -