golang find in string code example
Example 1: golang find string in string
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Contains("Assume", "Ass"))
fmt.Println(strings.ContainsAny("team", "i"))
fmt.Println(strings.ContainsAny("Hello", "aeiou&y"))
fmt.Println(strings.HasPrefix("Hello World", "Hello"))
fmt.Println(strings.HasSuffix("Hello World", "World"))
}
Example 2: golang find in string
// 1. Contains
res := strings.Contains(str, substr)
fmt.Println(res) // true