ADVERTISEMENT
ADVERTISEMENT

Golang strconv.IsPrint() Function with Examples

Golang | strconv.IsPrint() Function: Here, we are going to learn about the IsPrint() function of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 07, 2021

strconv.IsPrint()

The IsPrint() function is an inbuilt function of the strconv package which is used to check whether the given rune is defined as printable by Go, with the same definition as unicode.IsPrint() function: As per the Go, IsPrint() returns true for the letters, numbers, punctuation, symbols and ASCII space.

Print characters include categories L, M, N, P, S and the ASCII space character. These categories are the same as the strconv.IsGraphic() function except that the only spacing character is ASCII space, U+0020.

  • Category L: The set of Unicode letters
  • Category M: The set of Unicode mark characters
  • Category N: The set of Unicode number characters
  • Category P: The set of Unicode punctuation characters
  • Category S: The set of Unicode symbol characters
  • ASCII space character: The white space having the Unicode value U+0020.

It accepts a parameter (rune) and returns true if the given rune is defined as a printable by Go; false, otherwise.

Syntax:

func IsPrint(r rune) bool

Parameter(s):

  • r : The rune value which is to be checked.

Return Value:

The return type of the IsPrint() function is a bool, it returns true if the given rune is defined as a printable by Go; false, otherwise.

Example 1:

// Golang program to demonstrate the
// example of strconv.IsPrint() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Println(strconv.IsPrint('x'))
	fmt.Println(strconv.IsPrint(' '))
	fmt.Println(strconv.IsPrint('!'))
	fmt.Println(strconv.IsPrint('☺'))
	fmt.Println(strconv.IsPrint('☘'))

	fmt.Println(strconv.IsPrint('\t'))
	fmt.Println(strconv.IsPrint('\n'))
	fmt.Println(strconv.IsPrint('\007'))
}

Output:

true
true
true
true
true
false
false
false

Example 2:

// Golang program to demonstrate the
// example of strconv.IsPrint() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x rune
	var result bool

	x = '☺'
	result = strconv.IsPrint(x)
	fmt.Printf("%T, %c\n", x, x)
	fmt.Printf("%T, %v\n", result, result)

	x = '\u2665'
	result = strconv.IsPrint(x)
	fmt.Printf("%T, %c\n", x, x)
	fmt.Printf("%T, %v\n", result, result)
}

Output:

int32, ☺
bool, true
int32, ♥
bool, true

Golang strconv Package »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.