29 lines
559 B
Go
29 lines
559 B
Go
package helpers
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// StringToInts converts comma-delimited string to int slice
|
|
func StringToInts(s string) []int {
|
|
if s == "" {
|
|
return []int{}
|
|
}
|
|
parts := strings.Split(s, ",")
|
|
ints := make([]int, len(parts))
|
|
for i, part := range parts {
|
|
ints[i], _ = strconv.Atoi(part)
|
|
}
|
|
return ints
|
|
}
|
|
|
|
// IntToString converts int slice to comma-delimited string
|
|
func IntsToString(ints []int) string {
|
|
strs := make([]string, len(ints))
|
|
for i, num := range ints {
|
|
strs[i] = strconv.Itoa(num)
|
|
}
|
|
return strings.Join(strs, ",")
|
|
}
|