ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.