[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

testing equality

Haris Bogdanovic

3/9/2009 10:31:00 AM

Hi.

When I try to test equality of two strings, for example:

if object1.string==object2.string then puts object1.string end

I get nothing printed even though two strings are equal.

Why ?

Thanks
3 Answers

Justin Collins

3/9/2009 10:42:00 AM

0

Haris Bogdanovic wrote:
> Hi.
>
> When I try to test equality of two strings, for example:
>
> if object1.string==object2.string then puts object1.string end
>
> I get nothing printed even though two strings are equal.
>
> Why ?
>
> Thanks
>

The best way is to try the code using irb and post the results if you
are still stuck.
Most likely, though, the objects you are comparing not really equal. Try
printing out the values before you compare them.

-Justin

Robert Klemme

3/9/2009 11:52:00 AM

0

2009/3/9 Justin Collins <justincollins@ucla.edu>:
> Haris Bogdanovic wrote:
>>
>> When I try to test equality of two strings, for example:
>>
>> if object1.string==object2.string then puts object1.string end
>>
>> I get nothing printed even though two strings are equal.
>>
>> Why ?

Apparently those objects are not equal.

> The best way is to try the code using irb and post the results if you are
> still stuck.
> Most likely, though, the objects you are comparing not really equal. Try
> printing out the values before you compare them.

And when doing that p is preferred to puts because it will reveal any
additional whitespace that you would not see otherwise.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end

Haris Bogdanovic

3/11/2009 8:35:00 PM

0

I got it. One string from comparison is from gets function so it has 'enter'
character added on the end.


"Haris Bogdanovic" <fbogdanovic@xnet.hr> wrote in message
news:gp2r50$usq$1@gregory.bnet.hr...
> Hi.
>
> When I try to test equality of two strings, for example:
>
> if object1.string==object2.string then puts object1.string end
>
> I get nothing printed even though two strings are equal.
>
> Why ?
>
> Thanks