toUpperCase(char ch) converts the character argument to uppercase using case mapping information from the UnicodeData file
func IsLetter(r rune) bool
IsLetter reports whether the given rune is a letter (category L)
Here we are showing how to convert characters to the uppercase letters in the Go language. Here variable chr is used to hold the read character. For reading the character create the reader using NewReader. Check the character read is an alphabet or not by using unicode.IsLetter(chr). If it is an alphabet convert that character into the uppercase letter using unicode.ToUpper(chr). Finally print the results. Given below are the steps which are used in the Go program.
STEP 1: Import the package fmt, bufio, os, unicode
STEP 2: Start function main()
STEP 3: Create a reader using NewReader as reader := bufio.NewReader(os.Stdin)
STEP 4: Read the character into variable chr as chr, _, _ := reader.ReadRune()
STEP 5: Check the character is an alphabet or not by using unicode.IsLetter(chr) in if
condition
STEP 6: If true convert the character using unicode.ToUpper(chr)
STEP 7: print the result using fmt.println()
package main
import (
"bufio"
"fmt"
"os"
"unicode"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter the character to be cThe Uppercase character of %c = %c\n", chr, up)
} else {
fmt.Printf("Please enter a valid alphabet\n")
}
}
Enter the character to be c The Uppercase character of b = B Enter the character to be c Please enter a valid alphabet