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

'TrimLeft' Has A Bug #35660

Closed
daysleep666 opened this issue Nov 18, 2019 · 2 comments
Closed

'TrimLeft' Has A Bug #35660

daysleep666 opened this issue Nov 18, 2019 · 2 comments

Comments

@daysleep666
Copy link

daysleep666 commented Nov 18, 2019

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

$ go version

go version go1.13.4 darwin/amd64

CODE

package main

import (
	"fmt"
	"strings"
)

var PrefixTagSortKey = "v1:ts:"

func main() {
	str := PrefixTagSortKey + "t"
	v := strings.TrimLeft(str, PrefixTagSortKey)
	fmt.Println(v)
}

What operating system and processor architecture are you using (go env)?

mac os

What did you do?

go run

What did you expect to see?

t

What did you see instead?

empty

@ALTree
Copy link
Member

ALTree commented Nov 18, 2019

Hi,

The second parameter of TrimLeft is a cutset, meaning that (from the documentation):

all leading Unicode code points contained in cutset [are] removed.

If the cutset is "v1:ts:", every single v, 1, :, t, and s character in the string will be removed.

You probably want TrimPrefix

To remove a prefix, use TrimPrefix instead.

Closing here, since this is working as intended.

@ALTree ALTree closed this as completed Nov 18, 2019
@daysleep666
Copy link
Author

Thanks your explain.

@golang golang locked and limited conversation to collaborators Nov 17, 2020
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