Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

golang
communitycreator
isprint
function
strconv

What is the strconv.IsPrint() function in Golang?

Maria Elijah

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Golang strconv.IsPrint() function

The 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:

  • letters
  • numerals
  • punctuation
  • symbols
  • ASCII space

To use the IsPrint() function, we use the import keyword to import the strconv package into our program.

Syntax


func IsPrint(r rune) bool

Parameter

  • r: This is the rune value to be checked.

Return value

The strconv.IsPrint() returns a boolean true if the given rune is defined as a printable by Golang. Otherwise, it returns a false.

Code

The following code shows how to use the strconv.IsPrint() in Golang.

package main
import (
"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'))
}
Using IsPrint() to check if symbols are printable

Explanation

  • 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.

RELATED TAGS

golang
communitycreator
isprint
function
strconv

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring