Skip to content

strings: TrimLeft fails in certain cases #61919

Closed

Description

@sanketsudake

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.

Activity

  1. merykitty commented on Aug 10, 2023

    @merykitty

    // 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.

  2. locked and limited conversation to collaborators on Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions