Standard library / strconv
strconv.AppendQuote()
Appends double-quoted Go string literal to dst. Returns the expanded slice; retain it even if the initial destination has enough capacity. Expected stdout: 'v="a\\nb"\n'.
Formal Syntax & Structure
go syntaxgo
func AppendQuote(dst []byte, s string) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | []byte | Destination byte slice; existing prefix is preserved. |
| s | string | Input text to parse, inspect or quote. |
Return Value
[]byte
Resulting byte slice, including original prefix.
Working Example
Example Snippetgo
package main
import ( "fmt" "strconv")
func main() { b := []byte("v=") b = strconv.AppendQuote(b, "a\nb") fmt.Println(string(b))}