Standard library / strings

strings.LastIndex()

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

Formal Syntax & Structure

go syntaxgo
func LastIndex(s, substr string) int

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
substrstringSubstring to search for.

Return Value

int

Returns the byte offset of the last exact occurrence, or -1.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  fmt.Println(strings.LastIndex("aba", "a"))}
Go Reference