Create a gist now

Instantly share code, notes, and snippets.

CopyDigits function ref
package main
// ref: https://blog.golang.org/go-slices-usage-and-internals
// 1234 <-- digits
import (
"fmt"
"io/ioutil"
"regexp"
)
var digitRegexp = regexp.MustCompile("[0-9]+")
func CopyDigits(filename string) []byte {
b, _ := ioutil.ReadFile(filename)
b = digitRegexp.Find(b)
return append([]byte{}, b...)
}
func main() {
digits := CopyDigits("./copy-digits.go")
fmt.Println(digits)
}
@takatoshiono
Owner
takatoshiono commented Aug 25, 2016 edited
$ go run copy-digits.go
[49 50 51 52]
@takatoshiono
Owner

https://blog.golang.org/go-slices-usage-and-internalsA more concise version of this function could be constructed by using append. This is left as an exercise for the reader. というのをやってみた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment