10 Years
Discussion Span
Last Post by JamesCherrill

Could someone help java code to read number of lines, words and characrters in paragragh .

You can count how may times the \n appears in the paragraph for lines.
For characters the total length of the paragraph String minus the characters: " ", " ", " ", ...
For words user String.split(" "); and count the length of the array minus the elements where you might an empty String with more than one length.

Or you can use regular expressions.


Yes that is a good way to do it. but when you do that you could use StringTokenizer class. it seperates a string to tokens. just change the delimeters to count sentences , lines ,words etc. I hope that could help.

every sencence finish with "."
every line finish with "\n"
every word finish with "\n" , " " , "." or ","


Daniweb member rules include
"Do ensure that all posts contain relevant content and substance and are not simply vehicles for external links"
We also discourage people from simp/ky posting complete solutions.In future please help by pointing people in the right direction.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.