Home »
Golang »
Golang Reference
Golang unicode.IsPrint() Function with Examples
Golang | unicode.IsPrint() Function: Here, we are going to learn about the IsPrint() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 17, 2021
unicode.IsPrint()
The IsPrint() function is an inbuilt function of the unicode package which is used to check whether the given rune r is defined as a printable character by Go Language. These characters include all letters, marks, numbers, punctuation, symbols, and the ASCII space characters, from the categories L, M, N, P, S, and the ASCII space character.
It accepts one parameter (r rune) and returns true if rune r is a printable character; false, otherwise.
Syntax
func IsPrint(r rune) bool
Parameters
- r : Rune type value to be checked whether it is a printable character or not.
Return Value
The return type of the unicode.IsPrint() function is a bool, it returns true if rune r is a printable character; false, otherwise.
Example 1
// Golang program to demonstrate the
// example of unicode.IsPrint() Function
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Println("unicode.IsPrint('1'):",
unicode.IsPrint('1'))
fmt.Println("unicode.IsPrint('G'):",
unicode.IsPrint('G'))
fmt.Println("unicode.IsPrint(' ')",
unicode.IsPrint(' '))
fmt.Println("unicode.IsPrint('\\t'):",
unicode.IsPrint('\t'))
fmt.Println("unicode.IsPrint('\\n'):",
unicode.IsPrint('\n'))
fmt.Println("unicode.IsPrint('ⅻ'):",
unicode.IsPrint('ⅻ'))
fmt.Println("unicode.IsPrint('g'):",
unicode.IsPrint('g'))
}
Output:
unicode.IsPrint('1'): true
unicode.IsPrint('G'): true
unicode.IsPrint(' ') true
unicode.IsPrint('\t'): false
unicode.IsPrint('\n'): false
unicode.IsPrint('ⅻ'): true
unicode.IsPrint('g'): true
Example 2
// Golang program to demonstrate the
// example of unicode.IsPrint() Function
package main
import (
"fmt"
"unicode"
)
func main() {
var r rune
var result bool
r = 'Y'
result = unicode.IsPrint(r)
if result == true {
fmt.Printf("%c is a printable character.\n", r)
} else {
fmt.Printf("%c is not a printable character.\n", r)
}
r = '8'
result = unicode.IsPrint(r)
if result == true {
fmt.Printf("%c is a printable character.\n", r)
} else {
fmt.Printf("%c is not a printable character.\n", r)
}
r = '\t'
result = unicode.IsPrint(r)
if result == true {
fmt.Printf("%c is a printable character.\n", r)
} else {
fmt.Printf("%c is not a printable character.\n", r)
}
}
Output:
Y is a printable character.
8 is a printable character.
is not a printable character.
Golang unicode Package »