Golang fmt.Sprintln() function example

package fmt

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

Golang fmt.Sprintln() function usage example

 package main

 import "fmt"

 func main() {
 chinese := "你好"

 english := "Hello"

 malay := "apa khabar"

 fmt.Println("Sprint has NO new line :")
 fmt.Print(fmt.Sprint(chinese + " " + english + " " + malay)) // no newline

 fmt.Println("SprintLN has NEW line :")
 fmt.Print(fmt.Sprintln(chinese + " " + english + " " + malay)) // add a newline
 fmt.Print(fmt.Sprintln(chinese + " " + english + " " + malay)) // add a newline

 }

Output :

Sprint has NO new line :

你好 Hello apa khabarSprintLN has NEW line :

你好 Hello apa khabar

你好 Hello apa khabar

Reference :

http://golang.org/pkg/fmt/#Sprintln

Advertisement