Justin Collins
6/12/2009 6:45:00 PM
Peter Tosh wrote:
> Justin Collins wrote:
>
>> Peter Tosh wrote:
>>
>>> thanks!
>>> Niels
>>>
>>>
>> Are you sure there are two backslashes, or is that just the escaping
>> backslash?
>>
>> irb(main):001:0> "c:\\test"
>> => "c:\\test"
>> irb(main):002:0> puts "c:\\test"
>> c:\test
>> => nil
>> irb(main):003:0> "c:\\test".length
>> => 7
>>
>>
>> -Justin
>>
>
> Thanks Justin, when I print out the length it comes to 7 => it is just
> the escaping backslash.
>
> But in my program I need to compare it to a string from the database:
> "c:\test". When Ruby internally stores it as "c:\\test", how do I
> compare the two?
>
> When use the debugger it looks like this:
> (rdb:1) pp @path
> "c:\\Test"
> (rdb:1) pp @path.length
> 7
>
>
> Niels
>
It is not stored like that internally, that is just how it is displayed.
You do not need to do anything special to compare them. Is the above the
string from the database? I would try seeing exactly what you are
getting from the database, then output them both via the same method
(pp, p, or puts, just be consistent) and see if they are the same. Then
try comparing them.
-Justin