Question

Hey I'm writting a code to count the numbers of letters and chacters in a sentence I type into an input box. My question is in order to count the letters and the spaces in between the letters what would I use to symbolize the spaces like I know how to count the letters but what would I use to count the spaces in between the words?

[340 byte] By [thehurricanea] at [2007-11-26 22:52:47]
# 1
Take a look at the Character class. It has some handy categorization methodsyou can use: http://java.sun.com/javase/6/docs/api/java/lang/Character.html
DrLaszloJamfa at 2007-7-10 12:15:39 > top of Java-index,Java Essentials,Java Programming...
# 2
String sentence = "hello world";String[] words = sentence.split(" ");int spaces = words.length -1;
floundera at 2007-7-10 12:15:39 > top of Java-index,Java Essentials,Java Programming...
# 3

> String sentence = "hello world";

> String[] words = sentence.split(" ");

> int spaces = words.length -1;

If you do this with sentence = "hello world " (note trailing space), spaces is still 1!

From the API for split:

<quote>

Trailing empty strings are therefore not included in the resulting array.

</quote>

DrLaszloJamfa at 2007-7-10 12:15:39 > top of Java-index,Java Essentials,Java Programming...