Related Articles

Related Articles

How to use strconv.IsPrint() Function in Golang?
  • Last Updated : 03 May, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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'))
  
}

chevron_right


Output:

true
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
      
    
}

chevron_right


Output:

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :