Standard library / strings

strings.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 string, r rune) int

Parameters & Attributes

NameTypeDescription
sstringInput 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 (  "fmt"  "strings")
func main() {  fmt.Println(strings.IndexRune("aé", 'é'))}
Go Reference