ADVERTISEMENT
ADVERTISEMENT

Golang strconv.QuoteRuneToASCII() Function with Examples

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

strconv.QuoteRuneToASCII()

The QuoteRuneToASCII() function is an inbuilt function of the strconv package which is used to get a single-quoted Go character literal representing the rune r. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by IsPrint() function.

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

Syntax:

func QuoteRuneToASCII(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 QuoteRuneToASCII() 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.QuoteRuneToASCII() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Println(strconv.QuoteRuneToASCII('☺'))
	fmt.Println(strconv.QuoteRuneToASCII('🙈'))
	fmt.Println(strconv.QuoteRuneToASCII('🙉'))
	fmt.Println(strconv.QuoteRuneToASCII('🙊'))
}

Output:

'\u263a'
'\U0001f648'
'\U0001f649'
'\U0001f64a'

Example 2:

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x rune
	var result string

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

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

Output:

int32, ☺
string, '\u263a'
int32, ♥
string, '\u2665'

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.