Golang strconv.IsGraphic() Function with Examples

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

strconv.IsGraphic()

The IsGraphic() function is an inbuilt function of the strconv package which is used to check whether the given rune is defined as a Graphic by Unicode. Graphic characters include letters, marks, numbers, punctuation, symbols, and spaces, from categories L, M, N, P, S, and Zs.

  • Category L: The set of Unicode letters
  • Category M: The set of Unicode mark characters
  • Category N: The set of Unicode number characters
  • Category P: The set of Unicode punctuation characters
  • Category S: The set of Unicode symbol characters
  • Category Zs: The set of Unicode characters (Separator, space)

It accepts a parameter (rune) and returns true if the given rune is defined as a Graphic by Unicode; false, otherwise.

Syntax:

func IsGraphic(r rune) bool

Parameter(s):

  • r : The rune value which is to be checked.

Return Value:

The return type of the IsGraphic() function is a bool, it returns true if the given rune is defined as a Graphic by Unicode; false, otherwise.

Example 1:

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Println(strconv.IsGraphic('x'))
	fmt.Println(strconv.IsGraphic(' '))
	fmt.Println(strconv.IsGraphic('!'))
	fmt.Println(strconv.IsGraphic('☺'))
	fmt.Println(strconv.IsGraphic('☘'))
	
	fmt.Println(strconv.IsGraphic('\n'))
	fmt.Println(strconv.IsGraphic('\007'))
}

Output:

true
true
true
true
true
false
false

Example 2:

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x rune
	var result bool

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

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

Output:

int32, ☺
bool, true
int32, ♥
bool, true

Golang strconv Package »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.