英文字母对应的Unicode编码
A~Z :65~90a~z :97~1220~9 : 48~57
如果想要知道字符串中的值是否是⼩写英⽂字符,不使⽤⼯具包的⼀种⽅法就是使⽤Unicode编码值,举例:
package mainimport ( \"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 mainimport ( \"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\")}
因篇幅问题不能全部显示,请点此查看更多更全内容