To replace a substring in a string in Go, you can use the `strings.Replace()` function.
In this example,
strings
package.str
with a value of "Hello World"
.Replace()
function from the strings
package to replace the substring "World"
with "Universe"
.str
.package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello World"
str = strings.Replace(str, "World", "Universe", -1)
fmt.Println(str)
}
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in Go language with well detailed examples.