How to use strconv.QuoteRuneToGraphic() Function in Golang?

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'
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.