Logo

Programming-Idioms

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

Idiom #62 Find substring position

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

Specify if i should be regarded as a character index or as a byte index.

Explain the behavior when y is not contained in x.

i = x:find(y)

note that in lua index start at 1
#include <string.h>
int i=(int)(x-strstr(x,y));

New implementation...