×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.IsControl() Function with Examples

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

unicode.IsControl()

The IsControl() function is an inbuilt function of the unicode package which is used to check whether the given rune is a control character. Control characters are defined under C (other) Unicode category.

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

Syntax

func IsControl(r rune) bool

Parameters

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

Return Value

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

Example 1

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

package main

import (
	"fmt"
	"unicode"
)

func main() {
	// 0x7f is Unicode code point of DEL
	fmt.Println(unicode.IsControl(0x7f))

	// 8 is Unicode code point of Backspace
	fmt.Println(unicode.IsControl(8))

	// 0x7e is Unicode code point of '~'
	fmt.Println(unicode.IsControl(0x7e))
}

Output:

true
true
false

Example 2

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

package main

import (
	"fmt"
	"unicode"
)

func main() {

	for i := 0; i < 128; i++ {
		if unicode.IsControl(rune(i)) == true {
			fmt.Printf("%d [Hex: %0x] is a control character\n", i, i)
		} else {
			fmt.Printf("%d [Hex: %0x] is not a control character\n", i, i)
		}

	}
}

Output:

0 [Hex: 0] is a control character
1 [Hex: 1] is a control character
2 [Hex: 2] is a control character
3 [Hex: 3] is a control character
4 [Hex: 4] is a control character
5 [Hex: 5] is a control character
6 [Hex: 6] is a control character
7 [Hex: 7] is a control character
8 [Hex: 8] is a control character
9 [Hex: 9] is a control character
10 [Hex: a] is a control character
11 [Hex: b] is a control character
12 [Hex: c] is a control character
13 [Hex: d] is a control character
14 [Hex: e] is a control character
15 [Hex: f] is a control character
16 [Hex: 10] is a control character
17 [Hex: 11] is a control character
18 [Hex: 12] is a control character
19 [Hex: 13] is a control character
20 [Hex: 14] is a control character
21 [Hex: 15] is a control character
22 [Hex: 16] is a control character
23 [Hex: 17] is a control character
24 [Hex: 18] is a control character
25 [Hex: 19] is a control character
26 [Hex: 1a] is a control character
27 [Hex: 1b] is a control character
28 [Hex: 1c] is a control character
29 [Hex: 1d] is a control character
30 [Hex: 1e] is a control character
31 [Hex: 1f] is a control character
32 [Hex: 20] is not a control character
33 [Hex: 21] is not a control character
34 [Hex: 22] is not a control character
35 [Hex: 23] is not a control character
36 [Hex: 24] is not a control character
37 [Hex: 25] is not a control character
38 [Hex: 26] is not a control character
39 [Hex: 27] is not a control character
40 [Hex: 28] is not a control character
41 [Hex: 29] is not a control character
42 [Hex: 2a] is not a control character
43 [Hex: 2b] is not a control character
44 [Hex: 2c] is not a control character
45 [Hex: 2d] is not a control character
46 [Hex: 2e] is not a control character
47 [Hex: 2f] is not a control character
48 [Hex: 30] is not a control character
49 [Hex: 31] is not a control character
50 [Hex: 32] is not a control character
51 [Hex: 33] is not a control character
52 [Hex: 34] is not a control character
53 [Hex: 35] is not a control character
54 [Hex: 36] is not a control character
55 [Hex: 37] is not a control character
56 [Hex: 38] is not a control character
57 [Hex: 39] is not a control character
58 [Hex: 3a] is not a control character
59 [Hex: 3b] is not a control character
60 [Hex: 3c] is not a control character
61 [Hex: 3d] is not a control character
62 [Hex: 3e] is not a control character
63 [Hex: 3f] is not a control character
64 [Hex: 40] is not a control character
65 [Hex: 41] is not a control character
66 [Hex: 42] is not a control character
67 [Hex: 43] is not a control character
68 [Hex: 44] is not a control character
69 [Hex: 45] is not a control character
70 [Hex: 46] is not a control character
71 [Hex: 47] is not a control character
72 [Hex: 48] is not a control character
73 [Hex: 49] is not a control character
74 [Hex: 4a] is not a control character
75 [Hex: 4b] is not a control character
76 [Hex: 4c] is not a control character
77 [Hex: 4d] is not a control character
78 [Hex: 4e] is not a control character
79 [Hex: 4f] is not a control character
80 [Hex: 50] is not a control character
81 [Hex: 51] is not a control character
82 [Hex: 52] is not a control character
83 [Hex: 53] is not a control character
84 [Hex: 54] is not a control character
85 [Hex: 55] is not a control character
86 [Hex: 56] is not a control character
87 [Hex: 57] is not a control character
88 [Hex: 58] is not a control character
89 [Hex: 59] is not a control character
90 [Hex: 5a] is not a control character
91 [Hex: 5b] is not a control character
92 [Hex: 5c] is not a control character
93 [Hex: 5d] is not a control character
94 [Hex: 5e] is not a control character
95 [Hex: 5f] is not a control character
96 [Hex: 60] is not a control character
97 [Hex: 61] is not a control character
98 [Hex: 62] is not a control character
99 [Hex: 63] is not a control character
100 [Hex: 64] is not a control character
101 [Hex: 65] is not a control character
102 [Hex: 66] is not a control character
103 [Hex: 67] is not a control character
104 [Hex: 68] is not a control character
105 [Hex: 69] is not a control character
106 [Hex: 6a] is not a control character
107 [Hex: 6b] is not a control character
108 [Hex: 6c] is not a control character
109 [Hex: 6d] is not a control character
110 [Hex: 6e] is not a control character
111 [Hex: 6f] is not a control character
112 [Hex: 70] is not a control character
113 [Hex: 71] is not a control character
114 [Hex: 72] is not a control character
115 [Hex: 73] is not a control character
116 [Hex: 74] is not a control character
117 [Hex: 75] is not a control character
118 [Hex: 76] is not a control character
119 [Hex: 77] is not a control character
120 [Hex: 78] is not a control character
121 [Hex: 79] is not a control character
122 [Hex: 7a] is not a control character
123 [Hex: 7b] is not a control character
124 [Hex: 7c] is not a control character
125 [Hex: 7d] is not a control character
126 [Hex: 7e] is not a control character
127 [Hex: 7f] is a control character

Golang unicode Package »




Comments and Discussions!

Load comments ↻





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