Standard library / strconv

strconv.Quote()

Returns a double-quoted Go string literal representing s, escaping quotes, backslashes and nonprintable bytes/runes as needed. Not a general JSON encoder. Expected stdout: '"a\\nb"\n'.

Formal Syntax & Structure

go syntaxgo
func Quote(s string) string

Parameters & Attributes

NameTypeDescription
sstringInput text to parse, inspect or quote.

Return Value

string

Encoded representation.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strconv")
func main() {  fmt.Println(strconv.Quote("a\nb"))}
Go Reference