Check string prefix golang
package main
import (
"fmt"
"strings"
)
func main() {
// Input string
str := "golang is a programming language"
// Prefix to check
prefix := "go"
// Check if the string starts with the specified prefix
if strings.HasPrefix(str, prefix) {
fmt.Printf("The string '%s' starts with the prefix '%s'\n", str, prefix)
} else {
fmt.Printf("The string '%s' does not start with the prefix '%s'\n", str, prefix)
}
}