HiveBrain v1.2.0
Get Started
← Back to all entries
patterngoCritical

No startswith,endswith functions in Go?

Submitted by: @import:stackoverflow-api··
0
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.

import "strings"

startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // true


play.golang.org

Code Snippets

import "strings"

startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // true

Context

Stack Overflow Q#13244048, score: 337

Revisions (0)

No revisions yet.