Proposal Details
as there many usage of Replace(old, new, 1). I Proposal to add ReplaceOnce to strings and bytes package. Like wise ReplaceAll.
func ReplaceOnce(s, old, new string) string {
return Replace(s, old, new, 1)
}
func ReplaceOnce(s, old, new []byte) []byte {
return Replace(s, old, new, 1)
}
Comment From: seankhliao
Many does not quite rise to the level of majority ~65% https://github.com/golang/go/issues/27864#issuecomment-424852672 when ReplaceAll was added. plus once we add a function, some other value will take over the top as spot.
Once is also longer than , 1, and arguably generates confusion about why it exists. All at least reduces confusion about negative numbers.
Comment From: zigo101
This got closed?
@seankhliao So you really think your opinion is always correct and you have the right to close any proposals? Please respect community members.
@aclements @ianlancetaylor
Comment From: zigo101
@aclements @ianlancetaylor
Kindly re-ping. We should respect community members and the proposal process.
Comment From: ianlancetaylor
I will reopen, but I agree that this seems unlikely to be accepted.
Comment From: TapirLiu
@cuiweixie
as there many usage of Replace(old, new, 1). ...
You should show some examples.
I don't know if there are uses cases of Replace with 2+ as the last arguments (a.k.a. neither 1 nor -1). In theory, the possibility is low.