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

Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides an IsGraphic() function which is used to check whether the rune is defined as a Graphic by Unicode or not.
Such type of characters includes letters, marks, numbers, punctuation, symbols, and spaces, from categories L, M, N, P, S, and Zs. To access IsGraphic() function you need to import strconv Package in your program with the help of import keyword.

Syntax:

func IsGraphic(x rune) bool

Parameter: This function takes one parameter of rune type, i.e., x.

Return value: This function returns true if the rune is defined as a Graphic by Unicode. Otherwise, return false.

Example 1:



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

import (
    "fmt"
    "strconv"
)

func main() {

    // Checking whether the rune is 
    // defined as a Graphic by Unicode
    // Using IsGraphic() function
    fmt.Println (strconv.IsGraphic('♥'))
    fmt.Println (strconv.IsGraphic('b'))
      
}

Output:

true
true

Example 2:

// Golang program to illustrate 
// strconv.IsGraphic() Function
package main
 
import (
    "fmt"
    "strconv"
)
 
func main() {

    // Checking whether the rune
    // is defined as a Graphic by Unicode
    // Using IsGraphic() function
    val1 := 'a'
    res1 := strconv.IsGraphic(val1)
    fmt.Printf("Result 1: %v", res1)
    
    val2 := '♦'
    res2 := strconv.IsGraphic(val2)
    fmt.Printf("\nResult 2: %v", res2)
   
    val3 := '\001'
    res3 := strconv.IsGraphic(val3)
    fmt.Printf("\nResult 3: %v", res3) 
}

Output:

Result 1: true
Result 2: true
Result 3: false
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.