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