×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.IsGraphic() Function with Examples

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

unicode.IsGraphic()

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

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

Syntax

func IsGraphic(r rune) bool

Parameters

  • r : Rune type value to be checked whether it is a graphic character or not.

Return Value

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

Example 1

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Println("unicode.IsGraphic('9'):",
		unicode.IsGraphic('9'))
	fmt.Println("unicode.IsGraphic('0'):",
		unicode.IsGraphic('0'))
	fmt.Println("unicode.IsGraphic('3'):",
		unicode.IsGraphic('3'))
	fmt.Println("unicode.IsGraphic('&'):",
		unicode.IsGraphic('&'))
	fmt.Println("unicode.IsGraphic('☺')",
		unicode.IsGraphic('☺'))
	fmt.Println("unicode.IsGraphic('🙈'):",
		unicode.IsGraphic('🙈'))
	fmt.Println("unicode.IsGraphic('!'):",
		unicode.IsGraphic('!'))
}

Output:

unicode.IsGraphic('9'): true
unicode.IsGraphic('0'): true
unicode.IsGraphic('3'): true
unicode.IsGraphic('&'): true
unicode.IsGraphic('☺') true
unicode.IsGraphic('🙈'): true
unicode.IsGraphic('!'): true

Example 2

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	var r rune
	var result bool

	r = '🙈'
	result = unicode.IsGraphic(r)
	if result == true {
		fmt.Printf("%c is a Graphic by Unicode.\n", r)
	} else {
		fmt.Printf("%c is not a Graphic by Unicode.\n", r)
	}

	r = '\t'
	result = unicode.IsGraphic(r)
	if result == true {
		fmt.Printf("%c is a Graphic by Unicode.\n", r)
	} else {
		fmt.Printf("%c is not a Graphic by Unicode.\n", r)
	}

	r = 'Ɐ'
	result = unicode.IsGraphic(r)
	if result == true {
		fmt.Printf("%c is a Graphic by Unicode.\n", r)
	} else {
		fmt.Printf("%c is not a Graphic by Unicode.\n", r)
	}
}

Output:

🙈 is a Graphic by Unicode.
	 is not a Graphic by Unicode.
Ɐ is a Graphic by Unicode.

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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