Golang strconv.QuoteRune() Function with Examples

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

strconv.QuoteRune()

The QuoteRune() 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 control 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 QuoteRune(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 QuoteRune() 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.QuoteRune() Function

package main

import (
	"fmt"
	"strconv"
)

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

Output:

'☺'
'🙈'
'🙉'
'🙊'

Example 2:

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x rune
	var result string

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

	x = '♥'
	result = strconv.QuoteRune(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.