Sunday, 12 May 2019

Go language: Format a string without printing


Using 'fmt.Sprintf', you can format a string without printing.

Signature
func Sprintf(format string, a ...interface{}) string

Example
str := fmt.Sprintf("Good Morning, I am %s, I am %d years old ", "Krishna", 30)

App.go
package main

import (
	"fmt"
)

func main() {
	str := fmt.Sprintf("Good Morning, I am %s, I am %d years old ", "Krishna", 30)

	fmt.Println(str)
}

Output
Good Morning, I am Krishna, I am 30 years old





Previous                                                 Next                                                 Home

No comments:

Post a Comment