Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

Idiom #39 Check if string contains a word

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

#include <string>
bool ok = s.find(word) != std::string::npos;

Check for find() result's equality to std::string enumerated value npos ; expression yields a boolean value.
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
Ok : Boolean := Index (S, Word) > 0;

New implementation...
< >
programming-idioms.org