Strings In Depth9 / 17
Up next

Index finds an offset

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "hello world"
	fmt.Println(strings.Index(s, "world"))
	// -1 when the substring is absent
	fmt.Println(strings.Index(s, "xyz"))
}
What you're solving

byte offset of a substring, or -1