×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.IsUpper() Function with Examples

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

unicode.IsUpper()

The IsUpper() function is an inbuilt function of the unicode package which is used to check whether the given rune r is an upper case letter.

It accepts one parameter (r rune) and returns true if rune r is an upper case letter; false, otherwise.

Syntax

func IsUpper(r rune) bool

Parameters

  • r : Rune type value to be checked whether it is an upper case letter or not.

Return Value

The return type of the unicode.IsUpper() function is a bool, it returns true if rune r is an upper case letter; false, otherwise.

Example 1

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Println("unicode.IsUpper('A'):",
		unicode.IsUpper('A'))
	fmt.Println("unicode.IsUpper('a'):",
		unicode.IsUpper('a'))
	fmt.Println("unicode.IsUpper('Ä'):",
		unicode.IsUpper('Ä'))
	fmt.Println("unicode.IsUpper('Æ'):",
		unicode.IsUpper('Æ'))
	fmt.Println("unicode.IsUpper('ῌ')",
		unicode.IsUpper('ῌ'))
	fmt.Println("unicode.IsUpper('G'):",
		unicode.IsUpper('G'))
	fmt.Println("unicode.IsUpper('\\a'):",
		unicode.IsUpper('\a'))
}

Output:

unicode.IsUpper('A'): true
unicode.IsUpper('a'): false
unicode.IsUpper('Ä'): true
unicode.IsUpper('Æ'): true
unicode.IsUpper('ῌ') false
unicode.IsUpper('G'): true
unicode.IsUpper('\a'): false

Example 2

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	var r rune
	var result bool

	r = 'G'
	result = unicode.IsUpper(r)
	if result == true {
		fmt.Printf("%c (%U) is an uppercase letter.\n", r, r)
	} else {
		fmt.Printf("%c (%U) is not an uppercase letter.\n", r, r)
	}

	r = 'Ä'
	result = unicode.IsUpper(r)
	if result == true {
		fmt.Printf("%c (%U) is an uppercase letter.\n", r, r)
	} else {
		fmt.Printf("%c (%U) is not an uppercase letter.\n", r, r)
	}

	r = 'Æ'
	result = unicode.IsUpper(r)
	if result == true {
		fmt.Printf("%c (%U) is an uppercase letter.\n", r, r)
	} else {
		fmt.Printf("%c (%U) is not an uppercase letter.\n", r, r)
	}

	r = 'g'
	result = unicode.IsUpper(r)
	if result == true {
		fmt.Printf("%c (%U) is an uppercase letter.\n", r, r)
	} else {
		fmt.Printf("%c (%U) is not an uppercase letter.\n", r, r)
	}
}

Output:

G (U+0047) is an uppercase letter.
Ä (U+00C4) is an uppercase letter.
Æ (U+00C6) is an uppercase letter.
g (U+0067) is not an uppercase letter.

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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