38 lines
688 B
Go
38 lines
688 B
Go
package format
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
// 字符串切片转int切片
|
|
func StrSlicToIntSlice(input []string) ([]int, error) {
|
|
newSlic := make([]int, 0, len(input))
|
|
for _, p := range input {
|
|
if p == "" {
|
|
continue
|
|
}
|
|
val, err := strconv.Atoi(p)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
newSlic = append(newSlic, val)
|
|
}
|
|
return newSlic, nil
|
|
}
|
|
|
|
// 字符串切片转int64切片
|
|
func StrSlicToInt64Slice(input []string) ([]int64, error) {
|
|
newSlic := make([]int64, 0, len(input))
|
|
for _, p := range input {
|
|
if p == "" {
|
|
continue
|
|
}
|
|
val, err := strconv.ParseInt(p, 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
newSlic = append(newSlic, val)
|
|
}
|
|
return newSlic, nil
|
|
}
|