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 fails in certain cases #61919

Closed
sanketsudake opened this issue Aug 10, 2023 · 1 comment
Closed

strings: TrimLeft fails in certain cases #61919

sanketsudake opened this issue Aug 10, 2023 · 1 comment

Comments

@sanketsudake
Copy link

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

$ go version
go version go1.20.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

https://go.dev/play/p/Abefs5j3At0

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

go env Output
$ go env

What did you do?

func main() {
	fmt.Println(strings.TrimLeft("user_support", "user_"))
	// Expected: support Actual: pport
	fmt.Println(strings.TrimLeft("user_conversation", "user_"))
	// Expected: conversation Actual: conversation
	fmt.Println(strings.TrimLeft("user_suconversation", "user_"))
	// Expected: suconversation Actual: conversation
}

https://go.dev/play/p/Abefs5j3At0

What did you expect to see?

TrimLeft output not expected in above cases. Output seems bit different when string contains su substring.

What did you see instead?

Please see above snippet.

@merykitty
Copy link

// TrimLeft returns a slice of the string s with all leading
// Unicode code points contained in cutset removed.
//
// To remove a prefix, use TrimPrefix instead.

In other word, cutset is interpreted as a character set, and the longest prefix of s whose characters are all in cutset is chosen and trimmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants