Created
October 4, 2017 15:44
-
-
Save gerep/2285701aaabc2985bc67ac4b77ec899c to your computer and use it in GitHub Desktop.
Placeholder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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