Thanks, didn't know we can split through char array.
Exercise - WordCount
2 years later
I'm learning Go and I'm leveraging the regexp module:
package main
import (
"fmt"
"io/ioutil"
"log"
"regexp"
)
func get_words_from(text []byte) [][]byte {
words := regexp.MustCompile("\\w+")
return words.FindAll(text, -1)
}
func main() {
filename := "main.go"
data, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d\n", len(get_words_from(data)))
}