Standard library / strings
strings.Replacer
Reusable non-overlapping replacement rules. Replace returns a string; WriteString writes directly to an io.Writer and returns bytes written and error. Safe for concurrent use. Expected stdout: 'xbx 3 <nil>\n'.
Formal Syntax & Structure
go syntaxgo
type Replacer struct { /* unexported fields */ }Working Example
Example Snippetgo
package main
import ( "fmt" "strings")
func main() { r := strings.NewReplacer("a", "x") var b strings.Builder n, e := r.WriteString(&b, "aba") fmt.Println(b.String(), n, e)}