编写一个 Go 程序来检查字符是否为小写字母。unicode.IsLower 函数用于查找 Rune 是否为小写字符。我们在 If else 语句(if unicode.IsLower(lwch))中使用此 IsLower 函数来查找给定的字符是否为小写字母。
package main
import (
"bufio"
"fmt"
"os"
"unicode"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Character to Check Lowercase = ")
lwch, _, _ := reader.ReadRune()
if unicode.IsLower(lwch) {
fmt.Println("You have Entered the Lowercase Character")
} else {
fmt.Println("The entered Character is Not the Lowercase")
}
}

Go 语言检查字符是否为小写字母的程序
在这个小写字母的例子中,我们将给定的字节字符转换为 Rune(if unicode.IsLower(rune(lwch))),然后使用 IsLower 函数。
package main
import (
"bufio"
"fmt"
"os"
"unicode"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Character to Check Lowercase = ")
lwch, _ := reader.ReadByte()
if unicode.IsLower(rune(lwch)) {
fmt.Println("You have Entered the Lowercase Character")
} else {
fmt.Println("The entered Character is Not the Lowercase")
}
}
SureshMac:GoExamples suresh$ go run charIsLower2.go
Enter Character to Check Lowercase = o
You have Entered the Lowercase Character
SureshMac:GoExamples suresh$ go run charIsLower2.go
Enter Character to Check Lowercase = M
The entered Character is Not the Lowercase
在这个 Golang 示例中,我们使用 If 条件(if lwch >= ‘a’ && lwch <= ‘z’)来检查给定的字符是否在 a 和 z 之间,如果是,则为小写字母。
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Character to Check Lowercase = ")
lwch, _ := reader.ReadByte()
if lwch >= 'a' && lwch <= 'z' {
fmt.Println("You have Entered the Lowercase Character")
} else {
fmt.Println("The entered Character is Not the Lowercase")
}
}
SureshMac:GoExamples suresh$ go run charIsLower3.go
Enter Character to Check Lowercase = l
You have Entered the Lowercase Character
SureshMac:GoExamples suresh$ go run charIsLower3.go
Enter Character to Check Lowercase = Y
The entered Character is Not the Lowercase
此程序使用 ASCII 值(if lwch >= 97 && lwch <= 122)来查找字符是否为小写字母。
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Character to Check Lowercase = ")
lwch, _ := reader.ReadByte()
if lwch >= 97 && lwch <= 122 {
fmt.Println("You have Entered the Lowercase Character")
} else {
fmt.Println("The entered Character is Not the Lowercase")
}
}
SureshMac:GoExamples suresh$ go run charIsLower4.go
Enter Character to Check Lowercase = q
You have Entered the Lowercase Character
SureshMac:GoExamples suresh$ go run charIsLower4.go
Enter Character to Check Lowercase = Z
The entered Character is Not the Lowercase