The strconv
package’s AppendQuoteRuneToASCII()
function is used to append the single-quoted Go character literal, representing r
(as generated by the QuoteRuneToASCII()
function) to dst
and returns the extended buffer.
func AppendQuoteRuneToASCII(dst []byte, r rune) []byte
dst
is a byte array to which the single-quoted character is to be appended literal.r
is the rune character to be appended.The function AppendQuoteRuneToASCII()
returns the extended buffer after appending the single-quoted character.
The following code shows how to implement the AppendQuoteRuneToASCII()
function in Go.
// Using strconv.AppendQuoteRuneToASCII() Functionpackage mainimport ("fmt""strconv")func main() {x := []byte("Empty")fmt.Println("Orignal value before AppendQuoteRuneToASCII()", string(x))fmt.Println()// Append a character (rune 108 is the Unicode of l)x = strconv.AppendQuoteRuneToASCII(x, 108)fmt.Println("The new value after AppendQuoteRuneToASCII()", string(x))fmt.Println()// Append emojix = strconv.AppendQuoteRuneToASCII(x, '🥰')x = strconv.AppendQuoteRuneToASCII(x, '🙉')fmt.Println("The new Values in the array after AppendQuoteRuneToASCII()", string(x))fmt.Println()}
main
.main()
function, the variable r
of the type rune, assign a value to it, and pass the variable in the AppendQuoteRuneToASCII()
function. This returns a single-quoted Go character literal, representing the given rune value. Finally, we display the result.Note: All the values assigned to variable
x
are appended to thedst
.