开发者

ruby binary string compare

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜