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) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| old | string | Sequence to replace. |
| new | string | Replacement 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")))}