Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: find nonletter characters

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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:

    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


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,609
    Thanks
    25
    Thanked 316 Times in 295 Posts

    Default 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.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    nesthead98 (August 16th, 2012)

  4. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: find nonletter characters

    Ah yes, each line contains spaces. Sorry about that. Thanks.

Similar Threads

  1. Two characters trancated
    By gena_mak in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 9th, 2012, 01:09 PM
  2. Help with UTF-8 characters into Oracle database
    By Scomage in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 13th, 2012, 11:26 AM
  3. [SOLVED] Strings and Characters
    By av8 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 4th, 2011, 05:39 PM
  4. Strings and Characters
    By av8 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2011, 03:21 PM
  5. finding unescaped XML characters
    By diptee in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 18th, 2010, 03:51 AM

Tags for this Thread