【发布时间】:2020-04-05 04:36:25
【问题描述】:
在 Golang 中检查字符串中的所有字符是大写还是小写的简单方法是什么?
另外,字符串有标点的情况如何处理?
查看这些示例:
package main
import (
"fmt"
"unicode"
)
func main() {
s := "UPPERCASE"
fmt.Println(s.IsUpper()) // Should print true
s = "lowercase"
fmt.Println(s.IsUpper()) // Should print false
s = "lowercase"
fmt.Println(s.IsLower()) // Should print true
s = "I'M YELLING AT YOU!"
fmt.Println(s.IsUpper()) // Should print true
}
注意:s.IsUpper() 和 s.IsLower() 并不真正存在,但如果能找到一个等价物就好了。
【问题讨论】:
-
使用
strings.ToUpper/Lower并将输出与输入进行比较。
标签: string go uppercase lowercase