# String Equality Operation

**URL:** <https://www.ruby-forum.com/t/string-equality-operation/129405>\
**Category:** IronRuby\
**Created:** [February 18, 2008, 10:01am UTC](https://www.ruby-forum.com/t/string-equality-operation/129405 "2008-02-18T10:01:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [February 18, 2008, 10:01am UTC](https://www.ruby-forum.com/t/string-equality-operation/129405/1 "2008-02-18T10:01:52Z")

</div>

Hi There,

I’m doing a bit of playing around with IronRuby and ticking along ok.  
One thing which I’m having difficulty with though is string equality  
between a string that’s come from an external object.

Example:

mystring = $external.MyMethod  
puts “mystring=#{mystring}.”

if mystring == ‘abcd’  
puts “Match.”  
else  
puts "No match.  
end

Output:

mystring=abcd.  
No Match.

So I can get the value from my external method ok but it’s not macthing  
up with the IronRuby string object.

Does anyone know whether this is something I’m doing wrong?

Regards,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [February 18, 2008, 10:21am UTC](https://www.ruby-forum.com/t/string-equality-operation/129405/2 "2008-02-18T10:21:06Z")

</div>

Found the answer for those that might come across this and are in the  
same boat:

[http://www.ruby-forum.com/topic/126197#new](http://www.ruby-forum.com/topic/126197#new)

Working Example:

mystring = $external.MyMethod.to\_s  
puts “mystring=#{mystring}.”

if mystring == ‘abcd’  
puts “Match.”  
else  
puts "No match.  
end

Output:

mystring=abcd.  
Match.

Regards,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [February 18, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/string-equality-operation/129405/3 "2008-02-18T16:15:23Z")

</div>

Aaron C.:

> mystring = $external.MyMethod.to\_s  
> puts “mystring=#{mystring}.”
> 
> if mystring == ‘abcd’  
> puts “Match.”  
> else  
> puts "No match.  
> end

If you look at the class of each of your strings you’ll find that they  
are currently different types. mystring should be a ClrString and ‘abcd’  
is a String. If you do mystring.to\_s == ‘abcd’ it should return true.

We’re working on a plan to unify all string types and do lazy  
conversions as necessary. We’re slammed doing MIX work so that won’t  
start happening until we’re locked down for MIX (at least a couple of  
weeks or so).

Thanks  
-John
