How do you write multi-line strings in Go?
The following snippet will print value of string variable in multiple lines.
Example
package main
import "fmt"
func main() {
// ########## Multiline Exmaple 1 ###########
multiLine1 := `Australia is a country and continent surrounded by the Indian and Pacific oceans. Its major cities
– Sydney, Brisbane, Melbourne, Perth, Adelaide – are coastal. Its capital, Canberra, is inland. The country is
known for its Sydney Opera House, the Great Barrier Reef, a vast interior desert wilderness called the Outback,
and unique animal species like kangaroos and duck-billed platypuses.`
fmt.Println(multiLine1)
// ########## Multiline Exmaple 2 ###########
multiline2 := "Line1 \n" +
"Line2 \n" +
"Line3 \n" +
"Line4"
fmt.Print(multiline2)
}
Most Helpful This Week
How do you handle HTTP client server alerting in Go?
Launches 10 Goroutines and each goroutine adding 10 values to a Channel
Cannot use <variable> (type <type>) as type <new-type> error in Golang
Golang program to demonstrates how to encode map data into a JSON string.
Unveiling the Potential of Quantum Computing in AI: A Game Changer for Industries
Golang program for implementation of Tower of Hanoi Algorithm