代码拉取完成,页面将自动刷新
package strs
import (
"strings"
"unicode"
)
/*
IsBlank checks if a string is whitespace or empty (""). Observe the following behavior:
goutils.IsBlank("") = true
goutils.IsBlank(" ") = true
goutils.IsBlank("bob") = false
goutils.IsBlank(" bob ") = false
Parameter:
str - the string to check
Returns:
true - if the string is whitespace or empty ("")
*/
func IsBlank(str string) bool {
strLen := len(str)
if str == "" || strLen == 0 {
return true
}
for i := 0; i < strLen; i++ {
if unicode.IsSpace(rune(str[i])) == false {
return false
}
}
return true
}
func IsNotBlank(str string) bool {
return !IsBlank(str)
}
func IsAnyBlank(strs ...string) bool {
for _, str := range strs {
if IsBlank(str) {
return true
}
}
return false
}
func DefaultIfBlank(str, def string) string {
if IsBlank(str) {
return def
} else {
return str
}
}
// IsEmpty checks if a string is empty (""). Returns true if empty, and false otherwise.
func IsEmpty(str string) bool {
return len(str) == 0
}
func IsNotEmpty(str string) bool {
return !IsEmpty(str)
}
func Substr(s string, start, length int) string {
bt := []rune(s)
if start < 0 {
start = 0
}
if start > len(bt) {
start = start % len(bt)
}
var end int
if (start + length) > (len(bt) - 1) {
end = len(bt)
} else {
end = start + length
}
return string(bt[start:end])
}
func Equals(a, b string) bool {
return a == b
}
func EqualsIgnoreCase(a, b string) bool {
return a == b || strings.ToUpper(a) == strings.ToUpper(b)
}
// RuneLen 字符成长度
func RuneLen(s string) int {
bt := []rune(s)
return len(bt)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。