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) []byte

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
old[]byteSequence to replace.
new[]byteReplacement 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"))))}
Go Reference