Results 1 to 6 of 6

Thread: Read and compare character strings

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Read and compare character strings

    Hello,
    In my program, I had a really strange result and I have not managed to fix it but my code seems correct. I read a xml file type line by line and I want a string reference. I arrived at the time that I want to know. In short, I want to read and compare the characters.
    Data: <title = Sport"tennis">
    Reference: <title = Sport"tennis">
    With data, the line of my xml file and reference the line I want. Yet the equality test between the two returns false. would you mind? I also place my code comparison:
    Code:
                    	if (! test.equals(test))
                    	{
                    		System.out.System.out.println("Give"+ test);
                    System.out.System.out.println("Reference"+ + test"\ n");
                    	}
                    	
                    	else
                    	{
                    		System.out.System.out.println("Sport is");
                    	}
    Last edited by TechGate; 27-01-2010 at 01:24 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Read and compare character strings

    Hello,
    I think the equality test between the two returns false. This is normal, they are identical. I hope this will help you, so if you can make changes in your code it would be much better.
    String test1 = "tennis";
    String test = "tennis";
    if (! test1.equals(test))
    / / equivalent to
    if (!true)
    / / Equivalent to
    if (false)
    Just change the following and see if the code works.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Read and compare character strings

    Hello,
    There is no API that manages the xml? That it might be easier. Otherwise I do not know how your file is fulfilled, but if a user has access, it just adds a space or not, and should test your work anymore. I think you need a modification in your code, if you are going with the same code, then I do not think the code will work properly and you will get the desired results.

  4. #4
    Join Date
    Dec 2009
    Posts
    263

    Re: Read and compare character strings

    Hi,
    In fact, I always display data and references is that my condition if lines are different. Yet as you signal they are identical so I should have "Sport found". is that it what you are saying. or I have to change some thing other than this. And if my code will not work properly with the mentioned methods or functions, then what I have to use, that is what methods or functions should I use.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Read and compare character strings

    Hi,
    I think you should add the following lines to your code, to work properly. Just use them in your code.
    System.out.System.out.println("test1 =" + + test "Size =" + test.length());
    System.out.System.out.println("test1 =" + + test1 "Size =" + LigneReference.length());
    Hope this methods will help you. If they do not work, them post what is the error and we will try to solution your problem.

  6. #6
    Join Date
    Dec 2009
    Posts
    263

    Re: Read and compare character strings

    Hello,
    Ok, I better understand there is a gap of three between the first and the second, which may explain this surprising result. Now for me to find or are extra spaces. Or find a method to remove all spaces and tabs might be best. If you have any other alternative for this, then do help me with them. I had tried some other methods, but truly speaking they did not worked for me.

Similar Threads

  1. Files and strings in C
    By An1990 in forum Software Development
    Replies: 2
    Last Post: 10-05-2012, 10:11 PM
  2. Replies: 3
    Last Post: 23-09-2011, 02:27 PM
  3. Compare character string in SQL
    By Captain Carrot in forum Software Development
    Replies: 5
    Last Post: 14-05-2010, 10:20 AM
  4. How to Compare Two Strings in C
    By Pratim in forum Software Development
    Replies: 3
    Last Post: 28-12-2009, 11:10 AM
  5. Create a function for comparing character strings
    By Zool in forum Software Development
    Replies: 3
    Last Post: 16-10-2009, 01:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,523,580.20065 seconds with 17 queries