Skip to content
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

Closed
DemoLiang opened this issue May 10, 2018 · 3 comments
Closed

strings.TrimLeft bug #25328

DemoLiang opened this issue May 10, 2018 · 3 comments

Comments

@DemoLiang
Copy link

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

@myitcv
Copy link
Member

myitcv commented May 10, 2018

I think you want https://godoc.org/strings#TrimPrefix instead.

@myitcv myitcv closed this as completed May 10, 2018
@DemoLiang
Copy link
Author

Thanks

@gopherbot
Copy link

Change https://golang.org/cl/121637 mentions this issue: strings: add note for new Go developers to TrimLeft and TrimRight

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>
@golang golang locked and limited conversation to collaborators Jun 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants