How do you check how many letters are in a Java string?
How do you check what letter is in a certain position in the string (i.e, the second letter of the string)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A)
http://download.oracle.com/javase/7/docs/api/java/lang/String.html#length%28%29
edit
If you want to count the number of a specific type of characters in a
String, then a simple method is to iterate through theStringchecking each index against your test case.where
TestCasecan beisLetter( ),isDigit( ), etc.Or if you just want to count everything but spaces, then do a check in the
ifliketemp != ' 'B)
http://download.oracle.com/javase/7/docs/api/java/lang/String.html#charAt%28int%29