Ruby String Comparison

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


String comparison needs another section to understand:

There are 2 equal comparison conditionals for ruby strings as follows:

a. == returns true if two objects are strings.
b. eql? returns true if two strings are equal in length and content.

Ruby String Comparison

#!/usr/bin/ruby
#File: rubystringcomparisontest.rb
 
newstring = String.new("string comparison test")
newstring = newstring.downcase
 
newstring1 = String.new("string comparison test 2")
 
 
puts "#{newstring}"
puts "#{newstring1}"
puts newstring.eql?(newstring1)
puts (newstring == newstring1)

Output would be:

string comparison test
string comparison test 2
false
true





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.