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: strings.Trim trims too much strings #19172

Closed
timakin opened this issue Feb 18, 2017 · 1 comment
Closed

strings: strings.Trim trims too much strings #19172

timakin opened this issue Feb 18, 2017 · 1 comment

Comments

@timakin
Copy link
Contributor

timakin commented Feb 18, 2017

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.Trim("2016-11-22T00:26:00+0000", "+0000"))
}

The result is 2016-11-22T00:26:, but I expected 2016-11-22T00:26:00.
Is this a bug or an expected one?

@ALTree
Copy link
Member

ALTree commented Feb 18, 2017

The second parameter of strings.Trim is a cutset. So if you use "+0000" you are asking Trim to trim every "+" and "0", from the left and from the right.

For example:

strings.Trim("1abc2", "12")

returns "abc".

So yes, that output is expected.

@ALTree ALTree closed this as completed Feb 18, 2017
@golang golang locked and limited conversation to collaborators Feb 18, 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