Просмотр исходного кода

Merge pull request #299 from marekchen/patch-1

fix start with or end with space,word count error
无闻 9 лет назад
Родитель
Сommit
e6124ce092
1 измененных файлов с 1 добавлено и 2 удалено
  1. 1 2
      eBook/exercises/chapter_12/word_letter_count.go

+ 1 - 2
eBook/exercises/chapter_12/word_letter_count.go

@@ -31,7 +31,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.Fields(input))
 	nrlines++
 }