How to add variable to string variable in golang

omalave picture omalave · Apr 14, 2018 · Viewed 46.7k times · Source

I'm trying to add a value to a variable string in golang, without use printf because I'm using revel framework and this is for a web enviroment instead of console, this is the case:

data := 14
response := `Variable string content`

so I can't get variable data inside variable response, like this

response := `Variable string 14 content`

Any idea?

Answer

mu is too short picture mu is too short · Apr 14, 2018

Why not use fmt.Sprintf?

data := 14
response := fmt.Sprintf("Variable string %d content", data)