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

proposal: strings: please add TrimLeftSpace/TrimRightSpace function since there exits TrimSpace #36693

Closed
LindseyScharpman opened this issue Jan 22, 2020 · 2 comments

Comments

@LindseyScharpman
Copy link

What version of Go are you using (go version)?

go version go1.13.5 darwin/amd64
@beoran
Copy link

beoran commented Jan 22, 2020

You can use strings.TrimRightFunc or strings.TrimRightFunc for this:

package main

import (
	"fmt"
	"strings"
	"unicode"
)



func main() {
	fmt.Printf("Trim right spaces: >%s<\n", strings.TrimRightFunc("  你好  ", unicode.IsSpace))
	fmt.Printf("Trim left spaces: >%s<\n", strings.TrimLeftFunc("  你好  ", unicode.IsSpace))
}

https://play.golang.org/p/Kw_dQHQqlKU

If you like, with this, you can easily define TrimLeftSpace and TrimRightSpace yourself.

@toothrot toothrot changed the title please add TrimLeftSpace/TrimRightSpace function since there exits TrimSapce strings: please add TrimLeftSpace/TrimRightSpace function since there exits TrimSpace Jan 22, 2020
@toothrot toothrot changed the title strings: please add TrimLeftSpace/TrimRightSpace function since there exits TrimSpace proposal: strings: please add TrimLeftSpace/TrimRightSpace function since there exits TrimSpace Jan 22, 2020
@gopherbot gopherbot added this to the Proposal milestone Jan 22, 2020
@toothrot
Copy link
Contributor

Thanks for the helpful example, @beoran.

@wannibar I'm going to close this issue, as there is insufficient justification in the original issue to change the standard library, and there is a trivial implementation. Please comment if you disagree, or have more reason as to why we should make this change in Go.

@golang golang locked and limited conversation to collaborators Jan 21, 2021
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

4 participants