From f97b4d23b12d1320f0ead912e6238f1b45453e7a Mon Sep 17 00:00:00 2001 From: iikira <2571583272@qq.com> Date: Wed, 1 Aug 2018 17:33:51 +0800 Subject: [PATCH] add SliceStringToInt --- pcsutil/converter/converter.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pcsutil/converter/converter.go b/pcsutil/converter/converter.go index b2385d90..e9ead0a7 100644 --- a/pcsutil/converter/converter.go +++ b/pcsutil/converter/converter.go @@ -81,6 +81,23 @@ func SliceStringToInt64(ss []string) (si []int64) { return } +// SliceStringToInt []string 转换为 []int +func SliceStringToInt(ss []string) (si []int) { + si = make([]int, 0, len(ss)) + var ( + i int + err error + ) + for k := range ss { + i, err = strconv.Atoi(ss[k]) + if err != nil { + continue + } + si = append(si, i) + } + return +} + // MustInt 将string转换为int, 忽略错误 func MustInt(s string) (n int) { n, _ = strconv.Atoi(s)