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

The func TrimLeft in the strings lib cannot trim right when "_" exists #68080

Closed
LannyYao opened this issue Jun 20, 2024 · 2 comments
Closed

Comments

@LannyYao
Copy link

LannyYao commented Jun 20, 2024

Go version

version go1.16.15 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\langyao\AppData\Local\go-build
set GOENV=C:\Users\langyao\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\langyao\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\langyao\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\langyao\sdk\go1.16.15
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\langyao\sdk\go1.16.15\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.15
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\langyao\Desktop\Self\projects\NZ\robot-callback\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\langyao\AppData\Local\Temp\go-build1439212609=/tmp/go-build -gno-record-gcc-switches

What did you do?

strings.TrimLeft("tmp_at_abc", "tmp_at_")

What did you see happen?

the result is "bc"

What did you expect to see?

the result should be "abc"

@thepudds
Copy link
Contributor

Note TrimLeft takes a cutset:

https://pkg.go.dev/strings#TrimLeft

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.

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

3 participants