Standard library / bytes
bytes.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, sep []byte) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| sep | []byte | Separator or search sequence. |
Return Value
int
Returns the byte offset of the first exact occurrence, or -1 if absent.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { fmt.Println(bytes.Index([]byte("égo"), []byte("go")))}