mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes, strings: add ReplaceAll
Credit to Harald Nordgren for the proposal in https://golang.org/cl/137456 and #27864. Fixes #27864 Change-Id: I80546683b0623124fe4627a71af88add2f6c1c27 Reviewed-on: https://go-review.googlesource.com/137855 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5a8c11ce3e
commit
ebdc0b8d68
4 changed files with 30 additions and 0 deletions
|
|
@ -874,6 +874,15 @@ func Replace(s, old, new string, n int) string {
|
|||
return string(t[0:w])
|
||||
}
|
||||
|
||||
// ReplaceAll returns a copy of the string s with all
|
||||
// non-overlapping instances of old replaced by new.
|
||||
// If old is empty, it matches at the beginning of the string
|
||||
// and after each UTF-8 sequence, yielding up to k+1 replacements
|
||||
// for a k-rune string.
|
||||
func ReplaceAll(s, old, new string) string {
|
||||
return Replace(s, old, new, -1)
|
||||
}
|
||||
|
||||
// EqualFold reports whether s and t, interpreted as UTF-8 strings,
|
||||
// are equal under Unicode case-folding.
|
||||
func EqualFold(s, t string) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue