Logo

Programming-Idioms

History of Idiom 39 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-07-31, 20:10:13

Version 3

2015-08-01, 17:50:55

Idiom #39 Check if string contains a word

Set boolean ok to true if string word is contained in string s as a substring, or to false otherwise.

Idiom #39 Check if string contains a word

Set boolean ok to true if string word is contained in string s as a substring, or to false otherwise.

Code
ok = s.indexOf(word) !== -1;
Comments bubble
indexOf returns -1 if the word isn't found.