Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

golang
strconv
graphics
communitycreator

How to use the strconv.IsGraphic() function in Golang

Maria Elijah

Overview

The strconv package in Golang includes an inbuilt function called IsGraphic(). It checks whether a particular rune is defined as a Graphic by Unicode. Letters, markings, numbers, punctuation, symbols, and spaces fall within the L, M, N, P, S, and Zs groups of graphic characters.

Syntax

func IsGraphic(r rune) bool

Parameter

  • r: This is the rune value to be checked.

Return value

The strconv.IsGraphic() function returns true if the given rune is defined as a Graphic by Unicode. Otherwise, it returns false.

Example

The following code shows how to implement the strconv.IsGraphic() function in Golang:

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

import (
    "fmt"
    "strconv"
)

func main() {

    // The function checks whether the rune  
    // is defined as a Graphic by Unicode
    // Using IsGraphic() function
    fmt.Println(strconv.IsGraphic('!'))
    fmt.Println (strconv.IsGraphic('♥'))
	fmt.Println(strconv.IsGraphic('☺'))
    fmt.Println(strconv.IsGraphic('~'))
	fmt.Println(strconv.IsGraphic('☘'))
    fmt.Println(strconv.IsGraphic('\007'))
    fmt.Println (strconv.IsGraphic('E'))
      
}
Implementation of the IsGraphic() method

Code explanation

In the above code, we use the IsGraphic() function to check whether the rune passed is defined as a Graphic by Unicode, in which case it returns true, and returns false otherwise.

RELATED TAGS

golang
strconv
graphics
communitycreator
RELATED COURSES

View all Courses

Keep Exploring