Logo

Programming-Idioms

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

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.

(setf ok (search word s))

Technically this sets ok to the position of the string. This is more idiomatic than setting it specifically to true, since all numbers are true in lisp. Can use (not (null ...)) if T is desired.
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
Ok : Boolean := Index (S, Word) > 0;

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