How to use the strconv.AppendQuoteToGraphic() function in Golang
Overview
The strconv package’s AppendQuoteToGraphic() function appends the double-quoted Go string literal representing s (as generated by QuoteToGraphic() function), to dst. It returns the extended buffer.
Syntax
func AppendQuoteToGraphic(dst []byte, s string) []byte
Parameters
dst: This is a byte array to which the double-quoted Go string literal is to be appended.s: This is the string to be appended.
Return value
The AppendQuoteToGraphic() function returns the extended buffer after appending the double-quoted Go string literal.
Code
The following code shows how to implement the AppendQuoteToGraphic() function in Golang:
// Using strconv.AppendQuoteToGraphic() Functionpackage mainimport ("fmt""strconv")func main() {s := []byte("Empty:")fmt.Println("Initial value before AppendQuoteToGraphic()", string(s))fmt.Println()// Append a strings = strconv.AppendQuoteToGraphic(s, "Welcome \u2766 to another shot on Golang,")fmt.Println("The new Value after AppendQuoteToGraphic()", string(s))fmt.Println()}
Explanation
- Line 4: We add the
mainpackage. - Lines 6 to 9: We import the necessary packages in the Golang project.
- Lines 11 to 21: We define the
main()function. Within themain()function:- Line 12: We define the variable
sof the string type. - Line 13: We use the
print()function to display the initial value. - Line 18: We assign a value to the
svariable, and pass the variable in theAppendQuoteToGraphic()function. This returns a double-quoted Go string literal representingvalue. - Line 19: Finally, we display the result.
- Line 12: We define the variable
Note: All the values assigned to the
svariable are appended todstof the[]bytetype.