Home »
Golang »
Golang Reference
Golang strconv.AppendQuoteRuneToASCII() Function with Examples
Golang | strconv.AppendQuoteRuneToASCII() Function: Here, we are going to learn about the AppendQuoteRuneToASCII() function of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 06, 2021
strconv.AppendQuoteRuneToASCII()
The AppendQuoteRuneToASCII() function is an inbuilt function of the strconv package which is used to append the single-quoted Go character literal representing the r (as generated by QuoteRuneToASCII() function), to dst and returns the extended buffer. Where dst is the first parameter of []byte type and r is the second parameter of rune type.
It accepts two parameters (dst, r) and returns the extended buffer.
Syntax
func AppendQuoteRuneToASCII(dst []byte, r rune) []byte
Parameters
- dst : A byte array (or byte slices) in which we have to append the single-quoted character literal.
- r : Rune character to be appended.
Return Value
The return type of AppendQuoteRuneToASCII() function is a []byte, it returns the extended buffer after appending the single-quoted character.
Example 1
// Golang program to demonstrate the
// example of strconv.AppendQuoteRuneToASCII() Function
package main
import (
"fmt"
"strconv"
)
func main() {
x := []byte("QuoteRuneToASCII:")
fmt.Println("Before AppendQuoteRuneToASCII()")
fmt.Println(string(x))
// Appending a character
// [rune 97 - Unicode of a]
x = strconv.AppendQuoteRuneToASCII(x, 97)
fmt.Println("After AppendQuoteRuneToASCII()")
fmt.Println(string(x))
// Appending an emotion (emoji)
x = strconv.AppendQuoteRuneToASCII(x, '🥰')
fmt.Println("After AppendQuoteRuneToASCII()")
fmt.Println(string(x))
}
Output:
Before AppendQuoteRuneToASCII()
QuoteRuneToASCII:
After AppendQuoteRuneToASCII()
QuoteRuneToASCII:'a'
After AppendQuoteRuneToASCII()
QuoteRuneToASCII:'a''\U0001f970'
Example 2
// Golang program to demonstrate the
// example of strconv.AppendQuoteRuneToASCII() Function
package main
import (
"fmt"
"strconv"
)
func main() {
x := []byte("QuoteRuneToASCII:")
fmt.Println("Before appending...")
fmt.Println("x:", string(x))
fmt.Println("Length(x): ", len(x))
// Appending characters & monkey facse
x = strconv.AppendQuoteRuneToASCII(x, 97)
x = strconv.AppendQuoteRuneToASCII(x, '🙈')
x = strconv.AppendQuoteRuneToASCII(x, '🙉')
x = strconv.AppendQuoteRuneToASCII(x, '🙊')
fmt.Println("After appending...")
fmt.Println("x:", string(x))
fmt.Println("Length(x): ", len(x))
}
Output:
Before appending...
x: QuoteRuneToASCII:
Length(x): 17
After appending...
x: QuoteRuneToASCII:'a''\U0001f648''\U0001f649''\U0001f64a'
Length(x): 56
Golang strconv Package »