ls 5 years ago
parent
commit
26876c68f9
1 changed files with 40 additions and 0 deletions
  1. 40 0
      string.go

+ 40 - 0
string.go

@@ -0,0 +1,40 @@
+package tyr
+
+import (
+	"encoding/hex"
+	"unicode/utf8"
+)
+
+// StrLen utf8 string length
+func StrLen(s string) int {
+	return utf8.RuneCountInString(s)
+}
+
+// CheckCharYesNo check Y or N
+func CheckCharYesNo(s string) bool {
+	if s == "Y" {
+		return true
+	}
+	if s == "N" {
+		return true
+	}
+
+	return false
+}
+
+// CheckStringLength 检测字符串是否符合指定长度范围
+func CheckStringLength(s string, min, max int) bool {
+	n := utf8.RuneCountInString(s)
+	if n < min || n > max {
+		return false
+	}
+	return true
+}
+
+// IsHexString 字符串是否 16 进制解码字符串
+func IsHexString(s string) bool {
+	if _, err := hex.DecodeString(s); err != nil {
+		return false
+	}
+	return true
+}