3 Replies Latest reply: Mar 2, 2009 10:17 PM by 843785 RSS

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

      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! :)


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