3 Replies Latest reply on Mar 3, 2009 4:17 AM by 843785

    int numberOfWords = sentence.trim().split(" ").length;

    843785
      int numberOfWords = sentence.trim().split(" ").length;

      Hey everyone. I was just reading through some posts and I saw this as a way to count words in a sentence. I then went into the string section of the API to try to make sense of it. I understand that "trim" gets rid of the white space at the beginning and end and that "split" along with the given parameter splits the string each time there is a space. However, I dont get how these combined with length gives the number of words. Thanks! :)

      -M@

      EDIT: Wow it just hit me. I feel like a complete idiot. Disregard my question but thanks anyway! :)