0

SomeObject.find(20).client.full_name.downcase.bytes.each{|b| puts b}

  • 98 197 130 97 197 188 101 106 101 119 115

=> "błażejewsk" OtherClass.find(36).client.downcase.bytes.each {|b| puts b}

  • 98 197 129 97 197 187 101 106 101 119 115

=> "bŁaŻejewsk"

As you can see special characters have different bytes in both string . Both string have Encoding:UTF-8, so force_encoding or something like that , wouldn't help. == returns false. How should I convert those string so I can get true from comparison?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Adam Piotrowski
  • 654
  • 1
  • 6
  • 15

1 Answers1

1

It will not work with downcase see http://www.ruby-doc.org/core-2.1.0/String.html#method-i-downcase-21

Returns a copy of str with all uppercase letters replaced with their lowercase counterparts. The operation is locale insensitive—only characters “A” to “Z” are affected. Note: case replacement is effective only in ASCII region.

See this question to properly downcase UTF-8 strings Ruby 1.9: how can I properly upcase & downcase multibyte strings?

Community
  • 1
  • 1
poussma
  • 6,735
  • 3
  • 40
  • 65