How to use strconv.QuoteRuneToGraphic() Function in Golang?
Last Updated :
05 May, 2020
Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides a QuoteRuneToGraphic() function which is used to find a single-quoted Go character literal representing the rune. If the rune is not a Unicode graphic character as defined by IsGraphic, then the returned string will use a Go escape sequence (\t, \n, \xFF, \u0100). To access QuoteRuneToGraphic() function you need to import strconv Package in your program with the help of import keyword.
Syntax:
func QuoteRuneToGraphic(rn rune) string
Parameter: This function takes one parameter of rune type, i.e., rn.
Return value: This function returns a single-quoted Go string literal which represents rune.
Let us discuss this concept with the help of the given examples:
Example 1:
// Golang program to illustrate
// strconv.QuoteRuneToGraphic() Function
package main
import (
"fmt"
"strconv"
)
func main() {
// Finding a single-quoted Go
// string literal representing rune
// Using func QuoteRuneToGraphic() function
str := strconv.QuoteRuneToGraphic('♥')
fmt.Println (str)
}
Output:
'♥'
Example 2:
// Golang program to illustrate
// strconv.QuoteRuneToGraphic() Function
package main
import (
"fmt"
"strconv"
)
func main() {
// Finding a single-quoted Go
// string literal representing rune
// Using QuoteRuneToGraphic() function
val1 := strconv.QuoteRuneToGraphic('®')
fmt.Println("Result 1: ", val1)
val2 := strconv.QuoteRuneToGraphic('\u2666')
fmt.Println("Result 2: ", val2)
val3 := strconv.QuoteRuneToGraphic('\u000a')
fmt.Println("Result 3: ", val3)
}
Output:
Result 1: '®'
Result 2: '♦'
Result 3: '\n'
Share your thoughts in the comments
Please Login to comment...