placeholder gone when active
package main
import (
"fmt"
"strings"
)
func main() {
message := "Hello, [placeholder]! How are you, [placeholder]?"
replacements := map[string]string{
"[placeholder]": "John",
}
for placeholder, replacement := range replacements {
message = strings.ReplaceAll(message, placeholder, replacement)
}
fmt.Println(message)
}
This Go code snippet replaces [placeholder]
occurrences in the message
variable with the corresponding values provided in the replacements
map. The strings.ReplaceAll()
function is used within a loop that iterates over the replacements
map to substitute each placeholder with its associated replacement value. Finally, it prints the modified message
to the console.