×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.Is() Function with Examples

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

unicode.Is()

The Is() function is an inbuilt function of the unicode package which is used to check whether the given rune is a member of the specified table of ranges.

It accepts two parameters (rangeTab *RangeTable, r rune) and returns true if rune r is a member of the specified table of ranges; false, otherwise.

Syntax

func Is(rangeTab *RangeTable, r rune) bool

Parameters

  • rangeTab : Value of specified RangeTable in which we have to check rune r.
  • r : Rune type value to be checked as a member of the rangeTab.

Return Value

The return type of the unicode.Is() function is bool, it returns true if rune r is a member of the specified table of ranges; false, otherwise.

Example 1

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	result := unicode.Is(unicode.Latin, 'A')
	fmt.Println(result)

	result = unicode.Is(unicode.Latin, 'Ɐ')
	fmt.Println(result)

	result = unicode.Is(unicode.Latin, '&')
	fmt.Println(result)
}

Output:

true
true
false

Example 2

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Println("unicode.Is(unicode.Latin, 'x'):",
		unicode.Is(unicode.Latin, 'x'))

	fmt.Println("unicode.Is(unicode.ASCII_Hex_Digit, 'F'):",
		unicode.Is(unicode.ASCII_Hex_Digit, 'F'))

	fmt.Println("unicode.Is(unicode.White_Space, '\\t'):",
		unicode.Is(unicode.White_Space, '\t'))

	fmt.Println("unicode.Is(unicode.White_Space, '\\a'):",
		unicode.Is(unicode.White_Space, '\a'))
}

Output:

unicode.Is(unicode.Latin, 'x'): true
unicode.Is(unicode.ASCII_Hex_Digit, 'F'): true
unicode.Is(unicode.White_Space, '\t'): true
unicode.Is(unicode.White_Space, '\a'): false

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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