12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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
- }
|