[Go] Check whether a string ends with a specific suffix

Created on November 30, 2026

You can use strings.HasSuffix to check whether a string ends with a specified suffix.

package main

import (
    "fmt"
    "strings"
)

func main() {
    result := strings.HasSuffix("HelloWorld", "World")
    fmt.Println(result)
}
true
Go