Standard library / bytes

bytes.LastIndex()

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

Formal Syntax & Structure

go syntaxgo
func LastIndex(s, sep []byte) int

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
sep[]byteSeparator or search sequence.

Return Value

int

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

Working Example

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