Skip to content

strings: TrimRight() is not entirely right #46885

Closed

Description

@av86743

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

Activity

  1. ALTree commented on Jun 23, 2021

    @ALTree
    Member

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

  2. locked and limited conversation to collaborators on Jun 23, 2022
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