Results 1 to 12 of 12

Thread: using .equals

  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default using .equals

    i am trying to copy data from a text file, to a new one. one exception though. the user defines a line (or task) that they would like to modify. so what i did was read every line, and if it does not equal the line that the user wants to modify, we copy it over to the new .txt file.

    using .equals-image.png
    and then there are other tasks listed... the main point of this image, is to show that the two lines are identical...

    Java Code:
    System.out.println("orignial line: " + orignialLine);
    		while ((line = br.readLine()) != null) {
    			// if the line we are writing to, does not equal the new task, write
    			// it to the file
    			if (!line.trim().equals(orignialLine)) {
    				pw.println(line.trim());
    				System.out.println(line);
    				pw.flush();
    			}
    		}
    let me know if you need more code than this, as i would be happy to provide!

    thanks.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: using .equals

    Is there maybe a whitespace character: [ \t\n\x0B\f\r] ?
    Check the string length, print the char-array and so on....

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: using .equals

    Why is the first print from this statement on two lines? Is the first character a newline character?
    System.out.println("orignial line: " + orignialLine);
    The next print out does not skip a line.

  4. #4
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: using .equals

    that's interesting...

    new title豥o this!!!!󮌖5
    new title豥o this!!!!󮌖4

    it should only be 24 characters... that's odd...

    and i'm not sure why it's on two lines.

  5. #5
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: using .equals

    Quote Originally Posted by Norm View Post
    Why is the first print from this statement on two lines? Is the first character a newline character?
    System.out.println("orignial line: " + orignialLine);
    The next print out does not skip a line.
    are you saying it could be counting "\n" as a character possibly?

  6. #6
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: using .equals

    Because of that what i and norm believe --> there is a ne wline character at the beginning like "\nnew title豥o this!!!!2"
    System.out.print(orignialLine.toCharArray()) and print index [0] ! (as an int maybe...)

  7. #7
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: using .equals

    it looks like there is. i printed out the first character, and it gave me a new line break. that is weird, because it is the first line in the text. how can there be a new line break? lol, unless it is hidden :p

    what would the best way to fix this?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: using .equals

    how can there be a new line break?
    Hit Enter at the beginning of a line.
    what would the best way to fix this?
    I think the trim() method will remove it.

  9. #9
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: using .equals

    trim works like a charm! - thanks

    and what do you mean, by "hit enter at the beginning of the line? in the text file, or in eclipse?

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: using .equals

    I was answering your question: how can there be a new line break?

  11. #11
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: using .equals

    you have me curious now...

    using .equals-notepad.png

    how would a new line come about?

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: using .equals

    Put the cursor somewhere and press Enter

Similar Threads

  1. cant get .equals to work
    By Hooky75 in forum New To Java
    Replies: 14
    Last Post: 05-18-2011, 12:31 PM
  2. c always equals a*b
    By imorio in forum New To Java
    Replies: 3
    Last Post: 11-12-2010, 02:32 PM
  3. == and equals()
    By arefeh in forum New To Java
    Replies: 13
    Last Post: 01-05-2010, 04:56 PM
  4. == is same as .equals()??
    By DrMath in forum New To Java
    Replies: 1
    Last Post: 09-30-2009, 04:57 AM
  5. Replies: 0
    Last Post: 01-25-2008, 11:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •