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 )

it return a string.

package main

import "fmt"

func main() {

	var x = "John"
	var y = 36

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

	fmt.Println(s)
	// name is John, age is 36
}

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

Golang String

Golang

Compile and Run

String

Types and Values

Branching and Loop

Data Structure

Function

Misc

Examples

Reference