Introducing Radical.sh

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

Contains in Go

Contains function can be used to check if a substring is present in the main string. This is often useful if a portion of the string matches the known characters or to validate presence of certain characters. To get the exact position of substring, Index function to be used instead of contains.

Example : How to use contains function in Go Lang
package main

import (
    "fmt"
    "strings"
)

func main() {
    subString := "Phone"
    mainString := "iPhone"
    isPresent := strings.Contains(mainString, subString)
    fmt.Printf("Substring is present in main string ? %v\n", isPresent)
}

Output
Substring is present in main string ? true