Strings In Depth10 / 17
Up next

Replace and ReplaceAll

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "a-b-c-d"
	// replace every "-"
	fmt.Println(strings.ReplaceAll(s, "-", "_"))
	// replace only the first two
	fmt.Println(strings.Replace(s, "-", "_", 2))
}
What you're solving

substitute substrings