Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Placeholder
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
x := generateMessage("Hello {0}, you have {1} new messages!", "Gerep", "12")
fmt.Println(x)
}
func generateMessage(m string, p ...interface{}) string {
for k, v := range p {
i := strconv.Itoa(k)
m = strings.Replace(m, "{"+i+"}", fmt.Sprintf("%s", v), -1)
}
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment