find nonletter characters
I have a large document, and I'm looking for each line that contains a non-letter character. Trust that my method of getting each line's string is correct:
Code :
while (hasNextLine()) {
String line = nextLine();
linesearch:
for (int i = 0; i < line.length(); i++) {
if(!Character.isLetter(line.charAt(i))) {
System.out.println(line);
break linesearch;
}
}
}
This code doesn't work. It prints out every line in the document. I thought that the if statement would only print out the lines that contain a non-letter character, and then escape that line. What am I missing?
Thanks
Re: find nonletter characters
Put a print statement inside your if statement that prints: System.out.println(line.charAt(i));
That way we can see where it is seeing a non-letter character.
Does your line contain spaces? Because that would do it.
Re: find nonletter characters
Ah yes, each line contains spaces. Sorry about that. Thanks.