fusenapi/utils/format/str_to_int_slice.go
2023-06-05 10:18:31 +08:00

22 lines
365 B
Go

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
}