Im in the middle of doing something, while trawling through the Java API and any related forum threads i haven't found anything useful.
Basically i need to count the number of characters in a line from a file.
The file is already saved line by line in an array so hopefully it will just be a method to count next character while using something like scan.hasNext()
arraycount ++ // to print the next line of the array
charcount ++ // to work out the number of chars
This might not make much sense at the mo but all i need is a method to count characters in a line. I can work out the loops and prints.
String (Java 2 Platform SE v1.4.2)
Returns the length of this string.
Wow thanx, sorry i just seemed to get lost in the API!
The reason i was hoping for a charcounter is because the next task is to print the first 10 characters so that would be made easy with a loop
Thanks again, Ramya.
Do you want to include or omit whitespace characters. What about dots, commas etc...?
It's not actually specified if we count grammar. So i guess i can do it either way. Which ever way is easiest i can do. I can System.out.println("Number of characters:") or
("Number of Letters:")
Here is one way to print the first 10 characters of a string:
String st = "This is a long string";
Ah of course, thanx very much, Rich!
We learned to do that in the beginning, certainly makes things easier!
Ahem, for a substring of length 10, make that:
Originally Posted by RichWade
Well this is the done deal. I have 2 more tasks but they arent essential. One is to allow the user to search for a word then list the text with that word in caps. I wont bother with this.
The last one, which is annoying me, is to change the length of text to be printed and sotred by it all to <=300. As youy can see the array holds the entire text file (305 lines) but when i go to change the coe to just count < 299 anywhere it seems to throw up this error:
Exception in the "main" java.lang.ArrayIndexOutOfBoundsException : 299 at assignment.main(assignment.java:35)