Skip to content

Issue on strings.TrimRight("about.html", ".html") #20085

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

Closed
subchen opened this issue Apr 23, 2017 · 2 comments
Closed

Issue on strings.TrimRight("about.html", ".html") #20085

subchen opened this issue Apr 23, 2017 · 2 comments

Comments

@subchen
Copy link

subchen commented Apr 23, 2017

go 1.8.1
macos 10.12.4

I got abou, NOT about on following code

s := strings.TrimRight("about.html", ".html")
fmt.Print(s)

And I try other cases on strings.TrimRight(), they are all OK.

Why above case is failed? A bug?

@emidoots
Copy link

emidoots commented Apr 23, 2017

This isn't a bug. The Go issue tracker is also not for questions, please use the mailing list.

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

The cutset .html contains the letter t in the trailing part of the string, therefore the trailing t in about is removed. For example, see that strings.TrimRight("abouta.html", ".html") produces abouta -- that's because a is not in the trailing set.

For your case, you should be using TrimPrefix NOT TrimRight.

@subchen
Copy link
Author

subchen commented Apr 23, 2017

@slimsag, thanks for your explains. I should use TrimSuffix

@subchen subchen closed this as completed Apr 23, 2017
@golang golang locked and limited conversation to collaborators Apr 23, 2018
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