Explorar el Código

Update word_letter_count.go

marekchen hace 9 años
padre
commit
2838c9476b
Se han modificado 1 ficheros con 1 adiciones y 2 borrados
  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 += len(strings.Split(strings.Trim(input, " \n")," "))
+	nrwords += len(strings.Fields(input))
 	nrlines++
 }