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") }
原文地址:https://www.cnblogs.com/wanghui-garcia/p/10568924.html
时间: 2024-11-07 09:15:39