In golang, backquoted strings are used to create a string literals that contains the special characters and line breaks. These strings are also known as the “raw strings” and enclosed by backticks (`) instead of double quotes (“”).

In this article, we will see how to include a backquote in a backquoted string in golang.

Following is the way how we create the backquoted string in golang

str := `This is a
   multiline
   string`

By using a backslash character (\) we can escape a backquote character and include it inside a backquoted string. Following is the example:

str := `a \`backquote\` inside a backquoted string`

In the above example, the the backslash before the backquote tells the go compiler to interpret it as a character literal instead of the start or end of a backquoted string.

Categorized in:

Tagged in: