Home »
Golang »
Golang Reference
Golang unicode.IsLetter() Function with Examples
Golang | unicode.IsLetter() Function: Here, we are going to learn about the IsLetter() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 17, 2021
unicode.IsLetter()
The IsLetter() function is an inbuilt function of the unicode package which is used to check whether the given rune r is a letter (category L – the set of Unicode letters).
It accepts one parameter (r rune) and returns true if rune r is a letter; false, otherwise.
Syntax
func IsLetter(r rune) bool
Parameters
- r : Rune type value to be checked whether it is a letter or not.
Return Value
The return type of the unicode.IsLetter() function is a bool, it returns true if rune r is a letter; false, otherwise.
Example 1
// Golang program to demonstrate the
// example of unicode.IsLetter() Function
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Println("unicode.IsLetter('A'):",
unicode.IsLetter('A'))
fmt.Println("unicode.IsLetter('r'):",
unicode.IsLetter('r'))
fmt.Println("unicode.IsLetter(' '):",
unicode.IsLetter(' '))
fmt.Println("unicode.IsLetter('&'):",
unicode.IsLetter('&'))
fmt.Println("unicode.IsLetter('☺')",
unicode.IsLetter('☺'))
fmt.Println("unicode.IsLetter('🙈'):",
unicode.IsLetter('🙈'))
fmt.Println("unicode.IsLetter('!'):",
unicode.IsLetter('!'))
}
Output:
unicode.IsLetter('A'): true
unicode.IsLetter('r'): true
unicode.IsLetter(' '): false
unicode.IsLetter('&'): false
unicode.IsLetter('☺') false
unicode.IsLetter('🙈'): false
unicode.IsLetter('!'): false
Example 2
// Golang program to demonstrate the
// example of unicode.IsLetter() Function
package main
import (
"fmt"
"unicode"
)
func main() {
var r rune
var result bool
r = 'R'
result = unicode.IsLetter(r)
if result == true {
fmt.Printf("%c is a letter (category L).\n", r)
} else {
fmt.Printf("%c is not a letter (category L).\n", r)
}
r = '🙈'
result = unicode.IsLetter(r)
if result == true {
fmt.Printf("%c is a letter (category L).\n", r)
} else {
fmt.Printf("%c is not a letter (category L).\n", r)
}
r = 'Ɐ'
result = unicode.IsLetter(r)
if result == true {
fmt.Printf("%c is a letter (category L).\n", r)
} else {
fmt.Printf("%c is not a letter (category L).\n", r)
}
}
Output:
R is a letter (category L).
🙈 is not a letter (category L).
Ɐ is a letter (category L).
Golang unicode Package »