In Golang, you can use the strings.Contains() function from the "strings" package to check if a string contains a specific substring. Here's an example:
package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello, World!"
substr := "World"
// check if str contains substr
if strings.Contains(str, substr) {
fmt.Printf("'%s' contains '%s'\n", str, substr)
} else {
fmt.Printf("'%s' does not contain '%s'\n", str, substr)
}
}
Output:
'Hello, World!' contains 'World'
In this example, the strings.Contains() function is used to check if the string "Hello, World!" contains the substring "World". If it does, it prints that the string contains the substring. Otherwise, it prints that the string does not contain the substring.