Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@takatoshiono

takatoshiono Aug 25, 2016

$ go run copy-digits.go
[49 50 51 52]
Owner

takatoshiono commented Aug 25, 2016

$ go run copy-digits.go
[49 50 51 52]
@takatoshiono

This comment has been minimized.

Show comment Hide comment
@takatoshiono

takatoshiono Aug 25, 2016

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. というのをやってみた

Owner

takatoshiono commented Aug 25, 2016

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