Google News
logo
Golang - Interview Questions
Format a string without printing it
Find the easiest way to format a string with variables without printing the value.
 
Solution : The easiest way to format without printing is to use the fmt.Sprintf(), which returns a string without printing it.
 
For example :
package main

import "fmt"

func main() {
  s := fmt.Sprintf("Size: %d MB.", 90)
  fmt.Println(s)
}

Output : 

Size: 90 MB.

 

Advertisement