Reputation: 1705
I want to clarify my understanding of string comparison in Ruby.
How does Ruby compare binary strings?
Does it (a) split the strings on UTF-8 characters, compare strings based on the length of binary string in UTF-8 characters and values of UTF-8 characters, or (b) compare the strings on byte level?
Upvotes: 0
Views: 1685
Reputation: 21784
It depends on which version of Ruby you're using
In Ruby 1.8, strings are just a collection of bytes.
In Ruby 1.9, strings are a collection of encoded data.
String comparisons in Ruby 1.9 are done on the byte level, but some other operations like regex matches are not. It is best to normalize your String objects to the same encoding before comparing them.
Upvotes: 1