Standard library / strings

strings.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 string) string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
oldstringSequence to replace.
newstringReplacement sequence.

Return Value

string

Replaces every non-overlapping match; empty old matches at rune boundaries and at the start.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  fmt.Println(string(strings.ReplaceAll("a-a-a", "a", "b")))}
Go Reference