Standard library / strings

strings.Index()

Returns the byte offset of the first exact occurrence, or -1 if absent. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func Index(s, substr string) int

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
substrstringSubstring to search for.

Return Value

int

Returns the byte offset of the first exact occurrence, or -1 if absent.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  fmt.Println(strings.Index("égo", "go"))}
Go Reference