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: TrimRight() is not entirely right #46885

Closed
av86743 opened this issue Jun 23, 2021 · 1 comment
Closed

strings: TrimRight() is not entirely right #46885

av86743 opened this issue Jun 23, 2021 · 1 comment

Comments

@av86743
Copy link

av86743 commented Jun 23, 2021

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

Playground go1.16.5

Does this issue reproduce with the latest release?

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

Playground whatever.

What did you do?

Playground link

package main

import (
	"fmt"
	"strings"
	"runtime"
)

func main() {
	println(runtime.Version())

	ss := []string{ `Core.go`, `DebugInfo.go`, `Verifier.go` }
	sfx := `.go`
for _, s := range ss {
	s_ := strings.TrimRight(s, sfx)
	fmt.Println(s_)
}
}

What did you expect to see?

go1.16.5
Core
DebugInfo
Verifier

What did you see instead?

go1.16.5
Core
DebugInf
Verifier
@ALTree
Copy link
Member

ALTree commented Jun 23, 2021

TrimRight takes a cutset, which means that ALL ., g, and o on the right will be removed. What you want is TrimSuffix.

@ALTree ALTree closed this as completed Jun 23, 2021
@golang golang locked and limited conversation to collaborators Jun 23, 2022
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