You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The string replacer appears to have a problem with single replacements that would happen
at the start of a string:
s := "Hello World"
fmt.Println(strings.NewReplacer("Hello","").Replace(s))
fmt.Println(strings.NewReplacer("World","").Replace(s))
Produces:
Hello World
Hello
Which is incorrect. I would expect:
World
Hello
Whereas, when I add another substitution for replacement:
s := "Hello World"
fmt.Println(strings.NewReplacer("Hello","","l","").Replace(s))
fmt.Println(strings.NewReplacer("World","","l","").Replace(s))
Producing a correct result:
Word
Heo
Alternatively, if I perform a single replacement which is not at the start of the string:
s := "Hello World"
fmt.Println(strings.NewReplacer("ello","").Replace(s))
fmt.Println(strings.NewReplacer("orld","").Replace(s))
Produces the correct result:
H World
Hello W
So, the problem appears to be with single substitution when the match is at the start of
the string. I have noticed that strings.NewReplacer tries to handle single substitutions
as a special case... perhaps that code has a problem?
--------------
http://play.golang.org/p/Hj1V9d8fAj
go version devel +f4d1cb8d9a91 Thu Sep 19 22:34:33 2013 +1000 linux/386
The text was updated successfully, but these errors were encountered:
by orthopteroid:
The text was updated successfully, but these errors were encountered: