Golang 检查符文是否为小写字母

Golang 检查符文是否为小写字母

符文是ASCII的一个超集,或者说它是int32的一个别名。它容纳了世界上所有的书写系统中的字符,包括重音和其他变音符号,控制代码,如TAB和回车,并为每个字符分配了一个标准号。这个标准数字在Go语言中被称为Unicode码位或符文。
IsLower() 函数的帮助下,你可以检查给定符文是否为小写字母。如果给定的符文是小写字母,该函数返回真,如果给定的符文不是小写字母,则返回假。这个函数是在Unicode包中定义的,所以要使用这个方法,你需要在你的程序中导入Unicode包。

语法

func IsLower(r rune) bool

这个函数的返回类型是布尔型。让我们借助给定的例子来讨论这个概念。

例1 :

// Go program to illustrate how to check
// the given rune is a lowercase letter
// or not
package main
  
import (
    "fmt"
    "unicode"
)
  
// Main function
func main() {
  
    // Creating rune
    rune_1 := 'g'
    rune_2 := 'e'
    rune_3 := 'E'
    rune_4 := 'k'
    rune_5 := 'S'
  
    // Checking the given rune is 
    // a lower case letter or not
    // Using IsLower() function
    res_1 := unicode.IsLower(rune_1)
    res_2 := unicode.IsLower(rune_2)
    res_3 := unicode.IsLower(rune_3)
    res_4 := unicode.IsLower(rune_4)
    res_5 := unicode.IsLower(rune_5)
  
    // Displaying results
    fmt.Println(res_1)
    fmt.Println(res_2)
    fmt.Println(res_3)
    fmt.Println(res_4)
    fmt.Println(res_5)
  
}

输出

true
true
false
true
false

例2 :

// Go program to illustrate how to check
// the given rune is a lowercase letter
// or not
package main
  
import (
    "fmt"
    "unicode"
)
  
// Main function
func main() {
  
    // Creating a slice of rune
    val := []rune{'g', 'E', 'e', 'K', 's'}
  
    // Checking each element of the given slice
    // of the rune is a lowercase letter
    // Using IsLower() function
    for i := 0; i < len(val); i++ {
  
        if unicode.IsLower(val[i]) == true {
  
            fmt.Printf("\n%c is a lower case letter", val[i])
              
        } else {
          
            fmt.Printf("\n%c is not a lower case letter", val[i])
        }
    }
}

输出

g is a lower case letter
E is not a lower case letter
e is a lower case letter
K is not a lower case letter
s is a lower case letter

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程