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 4 of 4

Thread: Ignore certain characters in a string.

  1. #1
    Member
    Join Date
    Dec 2013
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ignore certain characters in a string.

    Hi, I'm trying to loop through a string and depending on the character, add a JLabel to a game. The problem is the character 'L' represents a lantern but is also used in the reply the game gives which is "LOOKREPLY". I've tried to use some code to ignore the LOOKREPLY bit but it's not working. Here's what I've tried.

    else if(message.charAt(i) == 'L' && message.charAt(i+1) != 'O' | message.charAt(i+1) == 'Y'){
    				JLabel localLabel = new JLabel();
    				localLabel.setIcon(lantern);
    				panel.add(localLabel);
    				panel.revalidate();
    				panel.repaint();

    But the first image on all of the JLabels is always a lantern, which is what L represents. As it's only 1 lantern this leads me to believe that it's ignoring the first 'L' but for some reason it's not ignoring the 'L' at the end of LOOKREPLY. Any idea why or perhaps a better way to go about this?

    Cheers.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Ignore certain characters in a string.

    code to ignore the LOOKREPLY
    Can you use one of the String class's methods to detect that String and ignore it?
    For example the equals() method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Dec 2013
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ignore certain characters in a string.

    I'm not sure how I would go about doing that as the string I'm using doesn't always begin with LOOKREPLY and always is followed by around 25 other characters.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Ignore certain characters in a string.

    Look at the String class's methods. There are some that might be useful.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Eliminating Unicode Characters and Escape Characters from String
    By bilalonjavaforum in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 19th, 2013, 05:26 AM
  2. Splitting a String by number of characters
    By torrie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 24th, 2013, 10:58 PM
  3. Replies: 2
    Last Post: March 28th, 2013, 09:54 AM
  4. Trouble with getting middle characters from a string.
    By doonar15 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 24th, 2013, 06:41 PM
  5. How to check whether the string contains only the specified characters ????
    By j_kathiresan in forum Java Theory & Questions
    Replies: 3
    Last Post: April 30th, 2010, 08:49 AM