Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Write multiline string in Go (Golang)

Posted on February 23, 2023February 23, 2023 by admin

A backquote (`) can be used to write a multiline string in Golang. Note that a string encoded in backquotes is a raw literal string and doesn’t honor any kind of escaping. Thus \n, \t are treated as a string literal when using back quotes

Working Code:

package main
import "fmt"
func main() {
multiline := `This is
a multiline
string`
fmt.Println(multiline)
}

Output

This is
a multiline
string
  • golang
  • Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2023 Welcome To Golang By Example | Design: Web XP