Skip to content

strings, bytes: Document behavior of Replace when old is empty #8143

@cespare

Description

@cespare
strings.Replace and bytes.Replace insert 'new' in between each rune when 'old' is empty:

strings.Replace("foo 世界", "", ".", -1) // .f.o.o.
.世.界.

Especially for package bytes, this behavior is a little surprising (one might expect new
to be inserted between each byte). It can't be changed, but it should at least be
documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions