Skip to content

Instantly share code, notes, and snippets.

@gerep
Created October 4, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerep/2285701aaabc2985bc67ac4b77ec899c to your computer and use it in GitHub Desktop.
Save gerep/2285701aaabc2985bc67ac4b77ec899c to your computer and use it in GitHub Desktop.
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