patterngoCritical
No startswith,endswith functions in Go?
Viewed 0 times
functionsstartswithendswith
Problem
Just curious to findout: why aren't there standard functions like startswith, endswith, etc as part of the standard libraries in the Go programming language?
Solution
The strings package contains HasPrefix and HasSuffix.
play.golang.org
import "strings"
startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // trueplay.golang.org
Code Snippets
import "strings"
startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // trueContext
Stack Overflow Q#13244048, score: 337
Revisions (0)
No revisions yet.