New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strings.TrimLeft bug #25328
Labels
Comments
I think you want https://godoc.org/strings#TrimPrefix instead. |
Thanks |
Change https://golang.org/cl/121637 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Jun 29, 2018
If one quickly looks at the strings package godoc, reading the name TrimLeft, one might think it removes a prefix from the string. The function's godoc does explain its purpose, but it's apparent that it is not clear enough, as there have been numerous raised issues about this confusion: #12771 #14657 #18160 #19371 #20085 #25328 #26119. These questions are also frequent elsewhere on the internet. Add a very short paragraph to the godoc, to hopefully point new Go developers in the right direction faster. Do the same thing for TrimRight and TrimSuffix. Change-Id: I4dee5ed8dd9fba565b4755bad12ae1ee6d277959 Reviewed-on: https://go-review.googlesource.com/121637 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.10 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOHOSTARCH="amd64"
GOHOSTOS="darwin"
What did you do?
just for a demo
func main() {
cfgs := "mongodb://off"
cfgs = strings.TrimLeft(cfgs, "mongodb://")
fmt.Printf("cfgs:%v\n",cfgs)
//output ==> cfgs:ff
}
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
//output ==> cfgs:off
What did you see instead?
//output ==> cfgs:ff
The text was updated successfully, but these errors were encountered: