×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang strconv.QuoteRuneToGraphic() Function with Examples

Golang | strconv.QuoteRuneToGraphic() Function: Here, we are going to learn about the QuoteRuneToGraphic() function of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 10, 2021

strconv.QuoteRuneToGraphic()

The QuoteRuneToGraphic() function is an inbuilt function of the strconv package which is used to get a single-quoted Go character literal representing the rune r. If the rune is not a Unicode graphic character, as defined by IsGraphic() function, the returned string will use a Go escape sequence (\t, \n, \xFF, \u0100).

It accepts a parameter (r) and returns a single-quoted Go character literal representing the rune r.

Syntax

func QuoteRuneToGraphic(r rune) string

Parameters

  • r : The rune value is to be returned with a single-quoted Go character literal representing the rune r.

Return Value

The return type of the QuoteRuneToGraphic() function is a string, it returns a single-quoted Go character literal representing the given rune value.

Example 1

// Golang program to demonstrate the
// example of strconv.QuoteRuneToGraphic() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Println(strconv.QuoteRuneToGraphic('☺'))
	fmt.Println(strconv.QuoteRuneToGraphic('🙈'))
	fmt.Println(strconv.QuoteRuneToGraphic('🙉'))
	fmt.Println(strconv.QuoteRuneToGraphic('🙊'))
	fmt.Println("----")

	fmt.Println(strconv.QuoteRuneToGraphic('\u263a'))
	fmt.Println(strconv.QuoteRuneToGraphic('\U0001f648'))
	fmt.Println(strconv.QuoteRuneToGraphic('\U0001f649'))
	fmt.Println(strconv.QuoteRuneToGraphic('\U0001f64a'))
	fmt.Println("----")

	fmt.Println(strconv.QuoteRuneToGraphic('\u000a'))
	fmt.Println(strconv.QuoteRuneToGraphic('	'))
}

Output:

'☺'
'🙈'
'🙉'
'🙊'
----
'☺'
'🙈'
'🙉'
'🙊'
----
'\n'
'\t'

Example 2

// Golang program to demonstrate the
// example of strconv.QuoteRuneToGraphic() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x rune
	var result string

	x = '☺'
	result = strconv.QuoteRuneToGraphic(x)
	fmt.Printf("%T, %c\n", x, x)
	fmt.Printf("%T, %v\n", result, result)

	x = '\u2665'
	result = strconv.QuoteRuneToGraphic(x)
	fmt.Printf("%T, %c\n", x, x)
	fmt.Printf("%T, %v\n", result, result)
}

Output:

int32, ☺
string, '☺'
int32, ♥
string, '♥'

Golang strconv Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.