[Golang] String startswith and endswith


Go equivalent of Python string startswith and endswith methods.

Actually strings package in Go standard library already provides these two methods, but with different names. HasPrefix is Go's string startswith, and HasSuffix is Go's string endswith.

Go String starts with

import "strings"

// true
strings.HasPrefix("Gopher", "Go")

Run Example on Go Playground

Go String ends with

import "strings"

// true
strings.HasSuffix("Amigo", "go")

Run Example on Go Playground


References:

[1]func HasPrefix - strings - The Go Programming Language
[2]func HasSuffix - strings - The Go Programming Language