[Go] Check whether a string starts with a prefix

Created on November 30, 2026

Use strings.HasPrefix to check whether a string starts with a particular prefix. It returns a boolean.

package main

import (
    "fmt"
    "strings"
)

func main() {
    r := strings.HasPrefix("HelloWorld", "Hello")
    fmt.Println(r)
}
true

Reference

Go