Преглед изворни кода

fix start with or end with space,word count error

marekchen пре 9 година
родитељ
комит
982f6b1abd
1 измењених фајлова са 1 додато и 1 уклоњено
  1. 1 1
      eBook/exercises/chapter_12/word_letter_count.go

+ 1 - 1
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++
 }