Home »
Golang »
Golang Reference
Golang unicode.IsTitle() Function with Examples
Golang | unicode.IsTitle() Function: Here, we are going to learn about the IsTitle() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 17, 2021
unicode.IsTitle()
The IsTitle() function is an inbuilt function of the unicode package which is used to check whether the given rune r is a title case letter.
It accepts one parameter (r rune) and returns true if rune r is a title case letter; false, otherwise.
The title case character is used to capitalize the first character of a word such as the Latin capital letter 'D' with the small letter 'z' ( \u01F2 'Dž').Here is the list of Unicode title case characters: List of Unicode Characters of Category "Titlecase Letter"
Syntax
func IsTitle(r rune) bool
Parameters
- r : Rune type value to be checked whether it is a title case letter or not.
Return Value
The return type of the unicode.IsTitle() function is a bool, it returns true if rune r is a title case letter; false, otherwise.
Example 1
// Golang program to demonstrate the
// example of unicode.IsTitle() Function
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Println("unicode.IsTitle('A'):",
unicode.IsTitle('A'))
fmt.Println("unicode.IsTitle('a'):",
unicode.IsTitle('a'))
fmt.Println("unicode.IsTitle('Dž'):",
unicode.IsTitle('Dž'))
fmt.Println("unicode.IsTitle('Lj'):",
unicode.IsTitle('Lj'))
fmt.Println("unicode.IsTitle('ῌ')",
unicode.IsTitle('ῌ'))
fmt.Println("unicode.IsTitle('G'):",
unicode.IsTitle('G'))
fmt.Println("unicode.IsTitle('\\a'):",
unicode.IsTitle('\a'))
}
Output:
unicode.IsTitle('A'): false
unicode.IsTitle('a'): false
unicode.IsTitle('Dž'): true
unicode.IsTitle('Lj'): true
unicode.IsTitle('ῌ') true
unicode.IsTitle('G'): false
unicode.IsTitle('\a'): false
Example 2
// Golang program to demonstrate the
// example of unicode.IsTitle() Function
package main
import (
"fmt"
"unicode"
)
func main() {
var r rune
var result bool
r = 'Dž'
result = unicode.IsTitle(r)
if result == true {
fmt.Printf("%c (%U) is a title case letter.\n", r, r)
} else {
fmt.Printf("%c (%U) is not a title case letter.\n", r, r)
}
r = 'ῌ'
result = unicode.IsTitle(r)
if result == true {
fmt.Printf("%c (%U) is a title case letter.\n", r, r)
} else {
fmt.Printf("%c (%U) is not a title case letter.\n", r, r)
}
r = 'Lj'
result = unicode.IsTitle(r)
if result == true {
fmt.Printf("%c (%U) is a title case letter.\n", r, r)
} else {
fmt.Printf("%c (%U) is not a title case letter.\n", r, r)
}
r = 'G'
result = unicode.IsTitle(r)
if result == true {
fmt.Printf("%c (%U) is a title case letter.\n", r, r)
} else {
fmt.Printf("%c (%U) is not a title case letter.\n", r, r)
}
}
Output:
Dž (U+01C5) is a title case letter.
ῌ (U+1FCC) is a title case letter.
Lj (U+01C8) is a title case letter.
G (U+0047) is not a title case letter.
Golang unicode Package »