Sprintf in Go

Posted by GoDoc
Public (Editable by Users)

Sprintf formats according to a format specifier and returns the resulting string.

Go
Edit
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	const name, age = "Kim", 22
	s := fmt.Sprintf("%s is %d years old.\n", name, age)

	io.WriteString(os.Stdout, s) // Ignoring error for simplicity.
}