首页 > 其他 > 详细

英文字母对应的Unicode编码

时间:2019-03-20 23:52:25      阅读:527      评论:0      收藏:0      [点我收藏+]

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")
}

 

英文字母对应的Unicode编码

原文:https://www.cnblogs.com/wanghui-garcia/p/10568924.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!