Go replace all occurrences of a substring with another one
package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello, World! Hello, Universe!"
newStr := strings.ReplaceAll(str, "Hello", "Hi")
fmt.Println(newStr)
}
Explanation: - Import the necessary packages "fmt" and "strings". - Define the main function. - Create a string variable "str" with the original text. - Use the strings.ReplaceAll function to replace all occurrences of the substring "Hello" with "Hi" in the original string. - Store the result in the new string variable "newStr". - Print the new string to the console.