Open In App

How to use strconv.IsPrint() Function in Golang?

Improve
Improve
Like Article
Like
Save
Share
Report

Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides an IsPrint() function which is used to check whether the rune is defined as printable by Go or not with the same definition as unicode.IsPrint of letters, numbers, punctuation, symbols, and ASCII space. To access IsPrint() function you need to import strconv Package in your program with the help of import keyword.

Syntax:

func IsPrint(x rune) bool

Parameter: This function takes one parameter of rune type, i.e., x.

Return value: This function returns true if the rune is defined as a Graphic by Unicode. Otherwise, return false.

Example 1:




// Golang program to illustrate
// strconv.IsPrint() Function
package main
  
import (
    "fmt"
    "strconv"
)
  
func main() {
  
    // Checking whether the rune
    // is defined as printable by Go
    // Using IsPrint() function
    fmt.Println(strconv.IsPrint('?'))
    fmt.Println(strconv.IsPrint('b'))
  
}


Output:

true
true

Example 2:




// Golang program to illustrate
// strconv.IsPrint() Function
package main
    
import (
    "fmt"
    "strconv"
)
    
func main() {
   
    // Checking whether the rune 
    // is defined as printable by Go
    // Using IsPrint() function
    val1 := 'a'
    res1 := strconv.IsPrint(val1)
    fmt.Printf("Result 1: %v", res1)
       
    val2 := '?'
    res2 := strconv.IsPrint(val2)
    fmt.Printf("\nResult 2: %v", res2)
      
    val3 := '\001'
    res3 := strconv.IsPrint(val3)
    fmt.Printf("\nResult 3: %v", res3)
      
    
}


Output:

Result 1: true
Result 2: true
Result 3: false


Last Updated : 03 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads