Why do numeric string comparisons give unexpected results?

后端 未结 4 1550
生来不讨喜
生来不讨喜 2021-01-15 15:59
\'10:\' < \'1:\'
# => true

Can someone explain me why the result in the above example is true? If I just compare \'1:\' and \'2:\' I get the

4条回答
  •  无人共我
    2021-01-15 16:30

    The first character of each of your two strings are the same. And as Dave said in the comments, the second character of the first, '0', is less than ':', so the first string is less than the second.

提交回复
热议问题