Golang: Convert Value to String

By Xah Lee. Date: . Last updated: .

To convert a value to string, load the the package fmt, then use the function fmt.Sprintf. Example:

fmt.Sprintf(string, v1, v2 )

package main

import "fmt"

func main() {

	var x = "John"
	var y = 36

	var s = fmt.Sprintf("name is %v, age is %v", x, y)

	fmt.Println(s == "name is John, age is 36")

}

For the input types and output format, see Golang: Printf Verbs

Golang String