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
Golang program to implement Binary Tree
Undefined <variable/function> error in Golang
How append a slice to an existing slice in Golang?
Creating a Struct Instance Using a Struct Literal
Concurrency in Golang
Invalid operation: <variable> (type <type>) does not support indexing error in Golang
10 Countries Paying Highest Salaries to Cybersecurity Professionals
Cannot call non-function <variable> error in Golang
Golang program for implementation of ZigZag Matrix
Modernizing Legacy Applications: Critical Tips for Organizational Upgrades