Standard library / strings

strings.Replacer.Replace()

Applies the configured non-overlapping replacements and returns the result. Replacement text is not processed recursively. Expected stdout: 'bc\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Replacer) Replace(s string) string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.

Return Value

string

Applies the configured non-overlapping replacements and returns the result. Replacement text is not processed recursively.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  r := strings.NewReplacer("a", "b", "b", "c")  fmt.Println(r.Replace("ab"))}
Go Reference