How would I find...

Hey there, I am somewhat new to Java and I was wondering, if I had a string, how could I check it to see how many letters there are in it? Is there some sort of function to do this?
[188 byte] By [CrimesofParisa] at [2007-10-2 10:37:38]
# 1
.length()javadoc is your friend http://java.sun.com/j2se/1.4.2/docs/api/
dmbdmba at 2007-7-13 2:42:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Hmm... well I know that finds the length of a string, but I do not want to count the numbers or special characters.
CrimesofParisa at 2007-7-13 2:42:18 > top of Java-index,Java Essentials,Java Programming...
# 3

You could manually iterate over the characters with charAt() and then test Character.isLetter on each one, incrementing a count if true.

Or you could use regex's \p{Alpha}.

The first one is probably faster (but probably not signifiantly so in most contexts), and simpler if you don't know regex.

The second one leads to more compact code, and is more readable if you do know regex.

jverda at 2007-7-13 2:42:18 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks, but I made my own little function for this program :p
CrimesofParisa at 2007-7-13 2:42:18 > top of Java-index,Java Essentials,Java Programming...