Logo

Programming-Idioms

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

Idiom #341 Find substring last position

Set i to the position of the last occurrence of the string y inside the 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.

import "strings"
i := strings.LastIndex(x, y)

i is the byte index of y in x, not the character (rune) index.

i will be -1 if y is not found in x.

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