DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Richard Kirkcaldy Guest

    comparing strings


    Hi,
    I already know you can't compare strings using ==, so I've tried using the
    following code:-

    if (lblcurPass.getText().equals(curPass))

    However, even when lblcurPass and curPass are the same it will always return
    false. I've also tried compareTo, and that returns false.
    Using System.out.print I can display the two passwords, and they are indeed
    the same on screen.
    Comparing two strings in a seperate small applet also works fine

    What's going wrong?

    --
    Richard Kirkcaldy
    richard@technical-power.co.uk

  2. #2
    Richard Kirkcaldy Guest

    Re: comparing strings

    Don't know how I've fixed it, but if I copy the strings into new empty
    strings it works.

    And that's why I hate Java

    "Richard Kirkcaldy" <java.@127.0.0.1> wrote in message
    news:3cca960e$1@10.1.10.29...
    >
    > Hi,
    > I already know you can't compare strings using ==, so I've tried using the
    > following code:-
    >
    > if (lblcurPass.getText().equals(curPass))
    >
    > However, even when lblcurPass and curPass are the same it will always

    return
    > false. I've also tried compareTo, and that returns false.
    > Using System.out.print I can display the two passwords, and they are

    indeed
    > the same on screen.
    > Comparing two strings in a seperate small applet also works fine
    >
    > What's going wrong?
    >
    > --
    > Richard Kirkcaldy
    > richard@technical-power.co.uk




  3. #3
    MarkN Guest

    Re: comparing strings


    "Richard Kirkcaldy" <java.@127.0.0.1> wrote:
    >
    >Hi,
    >I already know you can't compare strings using ==, so I've tried using the
    >following code:-
    >
    >if (lblcurPass.getText().equals(curPass))
    >
    >However, even when lblcurPass and curPass are the same it will always return
    >false. I've also tried compareTo, and that returns false.
    >Using System.out.print I can display the two passwords, and they are indeed
    >the same on screen.
    >Comparing two strings in a seperate small applet also works fine
    >
    >What's going wrong?
    >
    >--
    >Richard Kirkcaldy
    >richard@technical-power.co.uk


    Try doing a .trim() on both strings.

    Why is the password in a Label or is that just your naming convention?

  4. #4
    markN Guest

    Re: comparing strings


    There must be a reasonable explaination.

    You shouldn't store values in labels or text boxes anyway. You should be
    using a domain object.

    Don't blame your lack of understanding on Java. Don't like Java? Don't
    go near VB.Net or C#.




  5. #5
    Soft Solution System Limited Guest

    Re: comparing strings

    Are you using the JPasswordField?

    use the following to get the actual string of the password:

    String pw = String.copyValueOf( lblcurPass().getPassword());

    then use the equals to compare string.


    "Richard Kirkcaldy" <richard@technical-power.co.uk> ¼¶¼g©ó¶l¥ó
    news:3ccac28f@10.1.10.29...
    > Don't know how I've fixed it, but if I copy the strings into new empty
    > strings it works.
    >
    > And that's why I hate Java
    >
    > "Richard Kirkcaldy" <java.@127.0.0.1> wrote in message
    > news:3cca960e$1@10.1.10.29...
    > >
    > > Hi,
    > > I already know you can't compare strings using ==, so I've tried using

    the
    > > following code:-
    > >
    > > if (lblcurPass.getText().equals(curPass))
    > >
    > > However, even when lblcurPass and curPass are the same it will always

    > return
    > > false. I've also tried compareTo, and that returns false.
    > > Using System.out.print I can display the two passwords, and they are

    > indeed
    > > the same on screen.
    > > Comparing two strings in a seperate small applet also works fine
    > >
    > > What's going wrong?
    > >
    > > --
    > > Richard Kirkcaldy
    > > richard@technical-power.co.uk

    >
    >




  6. #6
    Seamus Guest

    Re: comparing strings


    "Richard Kirkcaldy" <richard@technical-power.co.uk> wrote:
    >Don't know how I've fixed it, but if I copy the strings into new empty
    >strings it works.
    >
    >And that's why I hate Java
    >
    >"Richard Kirkcaldy" <java.@127.0.0.1> wrote in message
    >news:3cca960e$1@10.1.10.29...
    >>
    >> Hi,
    >> I already know you can't compare strings using ==, so I've tried using

    the
    >> following code:-
    >>
    >> if (lblcurPass.getText().equals(curPass))
    >>
    >> However, even when lblcurPass and curPass are the same it will always

    >return
    >> false. I've also tried compareTo, and that returns false.
    >> Using System.out.print I can display the two passwords, and they are

    >indeed
    >> the same on screen.
    >> Comparing two strings in a seperate small applet also works fine
    >>
    >> What's going wrong?
    >>
    >> --
    >> Richard Kirkcaldy
    >> richard@technical-power.co.uk

    >
    >

    Check the lengths of the strings, I guarantee they are not the same. There
    probably is a space or character messing up the comparison.


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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links