fusenapi/utils/format/str_to_int_slice.go

22 lines
365 B
Go
Raw Normal View History

2023-06-05 02:18:31 +00:00
package format
import (
"strconv"
)
// 字符串切片转int切片
func StrSlicToIntSlice(input []string) ([]int, error) {
priceSlic := make([]int, 0, len(input))
for _, p := range input {
if p == "" {
continue
}
price, err := strconv.Atoi(p)
if err != nil {
return nil, err
}
priceSlic = append(priceSlic, price)
}
return priceSlic, nil
}