Standard library / strings

strings.Replacer.WriteString()

Writes the replaced form of s to w; returns the byte count and any write error. Expected stdout: '2 <nil> é\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)

Parameters & Attributes

NameTypeDescription
wio.WriterDestination writer receiving the produced bytes.
sstringData to append or write.

Return Value

(n int, err error)

Writes the replaced form of s to w; returns the byte count and any write error.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  r := strings.NewReplacer("a", "é")  var b strings.Builder  n, e := r.WriteString(&b, "a")  fmt.Println(n, e, b.String())}
Go Reference