-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
43 lines (36 loc) · 830 Bytes
/
utils.go
File metadata and controls
43 lines (36 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package wg26
import (
"strconv"
"strings"
)
//
// Author: 陈哈哈 bitschen@163.com
//
// TrimZeroToInt64 删除前导0字符
func TrimZeroToInt64(card string) int64 {
card = strings.TrimLeft(card, "0")
return ToInt64(card)
}
// AppendZero 添加前导0字符
func AppendZero(txt string, max int) string {
s := max - len(txt)
zeros := ""
for i := 0; i < s; i++ {
zeros += "0"
}
return zeros + txt
}
// IsDigits 返回字符串是否全为数字
func IsDigits(str string) bool {
return strings.IndexFunc(str, func(c rune) bool {
return c < '0' || c > '9'
}) == -1
}
// IsCardSN 返回字符串是否为卡号。卡号包括前导0字符。
func IsCardSN(card string) bool {
return LengthCardSN == len(card) && IsDigits(card)
}
func ToInt64(v string) int64 {
r, _ := strconv.ParseInt(v, 10, 64)
return r
}