Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides a QuoteRune() function which is used to find a single-quoted Go string literal representing rune and the returned string uses Go escape sequences (\t, \n, \xFF, \u0100) to control characters and non-printable characters defined by IsPrint. To access QuoteRune() function you need to import strconv Package in your program.

Syntax:

func QuoteRune(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.

Example 1:

// Golang program to illustrate 
// strconv.QuoteRune() Function
package main

import (
    "fmt"
    "strconv"
)

func main() { 

    // Finding a single-quoted Go 
    // string literal representing rune
    // Using QuoteRune() function
    r := strconv.QuoteRune('♥')
    fmt.Println(r)

}

Output:

'♥'

Example 2:

// Golang program to illustrate
// strconv.QuoteRune() Function
package main

import (
    "fmt"
    "strconv"
)

func main() {

    // Finding a single-quoted Go 
    // string literal representing rune
    // Using QuoteRune() function
    val1 := strconv.QuoteRune('♣')
    fmt.Println("Result 1: ", val1)
    fmt.Println("Length 1: ", len(val1))

    val2 := strconv.QuoteRune('→')
    fmt.Println("Result 2: ", val2)
    fmt.Println("Length 2: ", len(val2))

}

Output:

Result 1:  '♣'
Length 1:  5
Result 2:  '→'
Length 2:  5

Last Updated : 03 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads