Logo

Programming-Idioms

History of Idiom 39 > diff from v16 to v17

Edit summary for version 17 by :

Version 16

2015-09-03, 21:06:16

Version 17

2015-10-18, 17:00:28

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;
Code
ok = s.indexOf(word) !== -1;
Comments bubble
indexOf returns -1 if the word isn't found.
Comments bubble
indexOf returns -1 if the word isn't found.