Skip to content

strings.TrimRight works not the same #24891

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

Closed
756445638 opened this issue Apr 17, 2018 · 1 comment
Closed

strings.TrimRight works not the same #24891

756445638 opened this issue Apr 17, 2018 · 1 comment

Comments

@756445638
Copy link

756445638 commented Apr 17, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.5 windows/amd64

Does this issue reproduce with the latest release?

no

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\backstage\newest\hmi-server\code\gopath;D:\golib
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\yuyang\AppData\Local\Temp\go-build583116219=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.181:4840", ":4840"))
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.182:4840", ":4840"))
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.183:4840", ":4840"))
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.184:4840", ":4840"))
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.185:4840", ":4840"))
	fmt.Println(strings.TrimRight("opc.tcp://188.0.0.186:4840", ":4840"))
}

What did you expect to see?

opc.tcp://188.0.0.181
opc.tcp://188.0.0.182
opc.tcp://188.0.0.183
opc.tcp://188.0.0.184
opc.tcp://188.0.0.185
opc.tcp://188.0.0.186

What did you see instead?

opc.tcp://188.0.0.181
opc.tcp://188.0.0.182
opc.tcp://188.0.0.183
opc.tcp://188.0.0.1
opc.tcp://188.0.0.185
opc.tcp://188.0.0.186

@ALTree
Copy link
Member

ALTree commented Apr 17, 2018

In TrimRight, the second parameter is a cutset: TrimRight(s string, cutset string), i.e. a set of individual characters to be trimmed.

Passing ":4840" doesn't mean "trim right at :4840", it means "trim all :, 4, 8, and 0 characters from the right". That's why for 188.0.0.184 the last 4 also gets trimmed.

Working as intended, closing this.

@ALTree ALTree closed this as completed Apr 17, 2018
@golang golang locked and limited conversation to collaborators Apr 17, 2019
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