From 982f6b1abd6c96021308fd15121e1867d861dc27 Mon Sep 17 00:00:00 2001 From: marekchen Date: Fri, 16 Dec 2016 01:30:40 +0800 Subject: [PATCH] fix start with or end with space,word count error --- eBook/exercises/chapter_12/word_letter_count.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eBook/exercises/chapter_12/word_letter_count.go b/eBook/exercises/chapter_12/word_letter_count.go index 405200b..00dc30c 100755 --- a/eBook/exercises/chapter_12/word_letter_count.go +++ b/eBook/exercises/chapter_12/word_letter_count.go @@ -32,6 +32,6 @@ func main() { func Counters(input string) { nrchars += len(input) - 2 // -2 for \r\n // count number of spaces, nr of words is +1 - nrwords += strings.Count(input, " ") + 1 + nrwords += len(strings.Split(strings.Trim(input, " \n")," ")) nrlines++ }