I needed to replace a specially coded tokens with their unicode representations. strings.NewReplacer made it clean and easy.
first, you pass to strings.NewReplacer a string array literal made up of old, new string pairs, like so var logicalReplacer = strings.NewReplacer( "%and", `∧`, //LOGICAL AND "%or", `∨`, //LOGICAL OR "%cap", `∩`, //INTERSECTION "%cup", `∪`, //UNION ) then you call Replace() on it passing the text you want to process: func main() { fmt.Println(logicalReplacer.Replace("x %and y")) fmt.Println(logicalReplacer.Replace("x %cap y")) } Try it https://play.golang.org/p/5QWQ_yM6QU <https://play.golang.org/p/mQISZ1o9qZ> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.