The strconv
package’s AppendQuoteToASCII()
function is used to append the double-quoted Go string literal, representing s
(as generated by QuoteToASCII()
function), to dst
and returns the extended buffer.
func AppendQuoteToASCII(dst []byte, s string) []byte
dst
: is a byte array to which the double-quoted character is appended literally.s
: is the string character to be appended.The function AppendQuoteToASCII()
returns the extended buffer after appending the double-quoted string.
The following code shows how to implement the AppendQuoteToASCII()
function in Go.
// Using strconv.AppendQuoteToASCII() Functionpackage mainimport ("fmt""strconv")func main() {x := []byte("Empty")fmt.Println("initial value in the array before Appending", string(x))fmt.Println()// Append a stringx = strconv.AppendQuoteToASCII(x, `"Keep learning! Keep Coding!"`)fmt.Println("The new value after Appending", string(x))fmt.Println()// Append a stringx = strconv.AppendQuoteToASCII(x, `"Golang is one of my favourite languages"`)fmt.Println("The new values", string(x))fmt.Println()// Append a stringx = strconv.AppendQuoteToASCII(x, `"Educative Shot"`)x = strconv.AppendQuoteToASCII(x, `"Go Programming Language"` )fmt.Println("The new value in the array", string(x))}
main
.main()
function, the variable x
of type string, assign a value to it, and pass the variable in the AppendQuoteToASCII()
function. This returns a double-quoted Go string literal representing the given string.Note: All the values assigned to variable x are appended to the dst.