Standard library / bytes

bytes.IndexRune()

Returns the byte offset of the first occurrence of r, or -1; RuneError also matches invalid UTF-8. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func IndexRune(s []byte, r rune) int

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
rruneUnicode code point.

Return Value

int

Returns the byte offset of the first occurrence of r, or -1; RuneError also matches invalid UTF-8.

Working Example

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