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.
- Ada
- C
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Haskell
- JS
- JS
- Java
- Java
- Kotlin
- Kotlin
- Lisp
- Lua
- Lua
- Lua
- Obj-C
- PHP
- PHP
- PHP
- Pascal
- Perl
- Python
- Ruby
- Rust
- Scala
- Smalltalk
- VB
ok = String.contains?(s, word)
ok = index(string, word) /= 0
ok = word `isInfixOf` s
var ok = s.indexOf(word) !== -1;
indexOf returns -1 if the word isn't found.
boolean ok = s.indexOf(word) != -1;
(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.
ok = s:find(word, 1, true) ~= nil
This checks that the found index is not nil.
ok = false
if s:find(word, 1, true) then ok = true end
ok = s:find(word, 1, true)
This sets ok to the starting index of the first occurrence of word, or nil if there is no occurrence. These results are truey and falsey respectively.
If you need ok to equate true or false, then see other implementation.
If you need ok to equate true or false, then see other implementation.
$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";
}
$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 = word in s
ok = s.include?(word)
ok := s includesSubstring: word.
Dim ok As Boolean = s.Contains(word)