Last updated on Sep 13, 2022 by Suraj Sharma
In this tutorial, you'll learn to convert a golang interface to a string
The fmt.Sprintf()
built-in function is used to convert an interface to a golang string.
The verb '%v'
is used for interface as '%d'
is used for Integer of base 10.
package main
import "fmt"
func main () {
var val interface{}
var str string
val = []string{"go", "programming", "language"}
str = fmt.Sprintf(val)
fmt.Printf(str) // "[go programming language]"
}
Related Solutions
Rate this post
Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.