strconv.IsPrint() functionThe IsPrint() function of the strconv package is used to check whether a given rune is defined as printable by Golang.
The print characters include the following:
To use the IsPrint() function, we use the import keyword to import the strconv package into our program.
func IsPrint(r rune) bool
r: This is the rune value to be checked.The strconv.IsPrint() returns a boolean true if the given rune is defined as a printable by Golang. Otherwise, it returns a false.
The following code shows how to use the strconv.IsPrint() in Golang.
package mainimport ("fmt" // format package"strconv")func main() {fmt.Println(strconv.IsPrint('x'))fmt.Println(strconv.IsPrint('?'))fmt.Println(strconv.IsPrint('-'))fmt.Println(strconv.IsPrint('\t'))fmt.Println(strconv.IsPrint('6'))fmt.Println(strconv.IsPrint('~'))fmt.Println(strconv.IsPrint('\007'))}
Line 1: We add the package main.
Lines 3-6: We import the necessary packages in our Golang project.
Lines 8-16: We define the main() function and check whether the rune is printable using IsPrint() by passing different symbols as parameters.