-
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
-
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
-
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?
-
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#.
-
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
>
>
-
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks