unicode.IsPrint()
functionThe IsPrint()
function in the Unicode package is used to determine whether the provided rune r is defined as a printable character in the Go language.
These characters include letters, markings, numerals, punctuation, symbols, and ASCII space characters from the categories L, M, N, P, S, and the ASCII space character.
Note: All the Unicode is divided into various categories.
func IsPrint(r rune) bool
r
: The rune type value to be checked whether it is a printable character or not.It returns a boolean type value.
The unicode.IsPrint()
function returns true if rune r is a printable character. Otherwise, false.
Note: We must import the Unicode package in the program.
The following code shows how to use the unicode.IsPrint()
function:
// Golang program// Using unicode.IsPrint() Functionpackage mainimport ("fmt""unicode")func main() {// declare valChar as type runevar r rune// declare result as type boolvar result bool// assigning valuer = 'b'// checks if the character is printable// stores the value in variable resultresult = unicode.IsPrint(r)// prints the valuefmt.Printf("\nIs %c a printable character? %t", r, result)// assigning valuer = '4'// checks if the character is printable// stores the value in variable resultresult = unicode.IsPrint(r)// prints the valuefmt.Printf("\nIs %c a printable character? %t",r , result)// assigning valuer = '?'// checks if the character is printable// stores the value in variable resultresult = unicode.IsPrint(r)// prints the valuefmt.Printf("\nIs %c a printable character? %t ",r , result)// assigning valuer = '~'// checks if the character is printable// stores the value in variable resultresult = unicode.IsPrint(r)// prints the valuefmt.Printf("\nIs %c a printable character? %t",r , result)}