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

Idiom #62 Find substring position

Set i to the position of string y inside string x, if exists.

#include <string.h>
int i=(int)(x-strstr(x,y));
#include <string>
int i = x.find(y);
var i = x.IndexOf(y);
import std.algorithm;
auto i = x.countUntil(y);
var i = x.indexOf(y);
import "strings"
i := strings.Index(x, y)
import Data.List
Just i <- (y `isPrefixOf`) `findIndex` (tails x)
let i = x.indexOf(y);
int i = x.indexOf(y);
i = x:find(y)
$i = mb_strpos($x, $y, 0, 'UTF-8');
i := Pos(y, x);
$i = index($x, $y);
i = x.find(y)
i = x.index(y)
let i = x.find(y).unwrap();

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Related idioms