×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.IsPunct() Function with Examples

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

unicode.IsPunct()

The IsPunct() function is an inbuilt function of the unicode package which is used to check whether the given rune r is a Unicode punctuation character (category P – the set of Unicode punctuation characters).

It accepts one parameter (r rune) and returns true if rune r is a punctuation character; false, otherwise.

Syntax

func IsPunct(r rune) bool

Parameters

  • r : Rune type value to be checked whether it is a punctuation character or not.

Return Value

The return type of the unicode.IsPunct() function is a bool, it returns true if rune r is a punctuation character; false, otherwise.

Example 1

// Golang program to demonstrate the
// example of unicode.IsPunct() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Println("unicode.IsPunct('!'):",
		unicode.IsPunct('!'))
	fmt.Println("unicode.IsPunct('?'):",
		unicode.IsPunct('?'))
	fmt.Println("unicode.IsPunct(';'):",
		unicode.IsPunct(';'))
	fmt.Println("unicode.IsPunct(','):",
		unicode.IsPunct(','))
	fmt.Println("unicode.IsPunct(':')",
		unicode.IsPunct(':'))
	fmt.Println("unicode.IsPunct('G'):",
		unicode.IsPunct('G'))
	fmt.Println("unicode.IsPunct(' '):",
		unicode.IsPunct(' '))
}

Output:

unicode.IsPunct('!'): true
unicode.IsPunct('?'): true
unicode.IsPunct(';'): true
unicode.IsPunct(','): true
unicode.IsPunct(':') true
unicode.IsPunct('G'): false
unicode.IsPunct(' '): false

Example 2

// Golang program to demonstrate the
// example of unicode.IsPunct() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	// constant with mixed type runes
	const mixed = "Hey, Alex! What's the matter with you?"

	fmt.Println("Punctuation characters are:")
	for _, c := range mixed {
		if unicode.IsPunct(c) == true {
			fmt.Printf("%c", c)
		}
	}
}

Output:

Punctuation characters are:
,!'?

Golang unicode Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.