Search code examples
gorevel

How to add variable to string variable in golang


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?


Solution

  • Why not use fmt.Sprintf?

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