ADVERTISEMENT
ADVERTISEMENT

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

Parameter(s):

  • 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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.