Finding the substring in a string is one of the most common tasks for developers. Most of the mainstream languages implement this in a standard library. Go is not an exception. This recipe describes the way Go implements this.
Finding the substring in a string
How to do it...
- Open the console and create the folder chapter02/recipe01.
- Navigate to the directory.
- Create the contains.go file with the following content:
package main
import (
"fmt"
"strings"
)
const refString = "Mary had a little lamb"
func main() {
lookFor := "lamb"
contain := strings.Contains(refString, lookFor)
fmt.Printf("The \"...