Standard library / bytes
bytes.ReplaceAll()
Replaces every non-overlapping match; empty old matches at rune boundaries and at the start. Expected stdout: 'b-b-b\n'.
Formal Syntax & Structure
go syntaxgo
func ReplaceAll(s, old, new []byte) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| old | []byte | Sequence to replace. |
| new | []byte | Replacement sequence. |
Return Value
[]byte
Replaces every non-overlapping match; empty old matches at rune boundaries and at the start.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { fmt.Println(string(bytes.ReplaceAll([]byte("a-a-a"), []byte("a"), []byte("b"))))}