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