Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Index of string in Go

Index function gets the position of first match in the main string, if the string is not found index returns -1.

package main

import (
    "fmt"
    "strings"
)

func main() {

    subString := "Phone"
    mainString := "iPhone"

    positionOfSubstring := strings.Index(mainString, subString)
    fmt.Printf("Index of substring is : %d\n", positionOfSubstring)

}

Output
Index of substring is : -1