Created
January 27, 2017 13:09
-
-
Save ik5/850c5dc1892c82c41be9c6d33c9fcb2a to your computer and use it in GitHub Desktop.
convert a list of items in a string to a uint64 list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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