Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
Ok : Boolean := Index (S, Word) > 0;
#include <string.h>
int ok = strstr(s,word) != NULL;
(require '[clojure.string :as string])
(def ok (string/includes? word s))
#include <string>
bool ok = s.find(word) != std::string::npos;
var ok = s.Contains(word);
import std.algorithm.searching;
bool ok = s.canFind(word);
var ok = s.contains(word);
ok = String.contains?(s, word)
Ok = string:str(S, Word) > 0.
ok = index(string, word) /= 0
import "strings"
ok := strings.Contains(s, word)
ok = word `isInfixOf` s
var ok = s.includes(word);
var ok = s.indexOf(word) !== -1;
boolean ok = s.contains(word);
val ok = s.contains(word)
val ok = word in s
(setf ok (search word s))
ok = s:find(word, 1, true)
ok = false
if s:find(word, 1, true) then ok = true end
ok = s:find(word, 1, true) ~= nil
@import Foundation;
BOOL ok=[s containsString:word];
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// N贸tese el uso de ===. Puesto que == simple no funcionar谩 como se espera
// porque la posici贸n de 'a' est谩 en el 1掳 (primer) caracter.
if ($pos === false) {
    echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
} else {
    echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
    echo " y existe en la posici贸n $pos";
}
$ok = str_contains($s, $word);
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// N贸tese el uso de ===. Puesto que == simple no funcionar谩 como se espera
// porque la posici贸n de 'a' est谩 en el 1掳 (primer) caracter.
if ($pos === false) {
    echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
} else {
    echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
    echo " y existe en la posici贸n $pos";
}
ok := pos(word,s)<>0;
$ok = index($s,$word) >= 0;
ok = word in s
ok = s.include?(word)
let ok = s.contains(word);
val ok = s.contains(word)
ok := s includesSubstring: word.
Dim ok As Boolean = s.Contains(word)