Skip to content

Instantly share code, notes, and snippets.

@ik5
Created January 27, 2017 13:09
Show Gist options
  • Save ik5/850c5dc1892c82c41be9c6d33c9fcb2a to your computer and use it in GitHub Desktop.
Save ik5/850c5dc1892c82c41be9c6d33c9fcb2a to your computer and use it in GitHub Desktop.
convert a list of items in a string to a uint64 list
package main
import (
"fmt"
"strconv"
"strings"
)
func toUin64(data, sep string) []uint64 {
fields := strings.Split(data, sep)
result := make([]uint64, len(fields))
for i, elem := range fields {
result[i], _ = strconv.ParseUint(elem, 10, 64)
}
return result
}
func main() {
s := "01,2,3,255"
fmt.Printf("%s = %v\n", s, toUin64(s, ","))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment