英文字母對應的Unicode編碼


A~Z :65~90

a~z :97~122

0~9 : 48~57

如果想要知道字符串中的值是否是小寫英文字符,不使用工具包的一種方法就是使用Unicode編碼值,舉例:

package main

import (
    "fmt"
)


func main() {
    // str := "helloworld" //返回str is all lower char
    str := "hello4world" //返回str is not all lower char
    for _, s := range str{
        if !(s > 96 && s < 123){
            fmt.Println("str is not all lower char")
            return
        }
    }
    fmt.Println("str is all lower char")
}

當然還有更簡單的一種方法:

package main

import (
    "fmt"
)

func main() {
    str := "helloworld" //返回str is all lower char
    // str := "hello4world" //返回str is not all lower char
    for _, s := range str{
        if !('a' <= s && s <= 'z'){
            fmt.Println("str is not all lower char")
            return
        }
    }
    fmt.Println("str is all lower char")
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM