Ruby start_with? inconsistency

Please tell me how the first use of start_with returned false.

enter image description here

Thank!

+3


source to share


1 answer


Your string may contain a hidden unicode character.

If so, the line starts with that character, not with #

, which is why you get false

.

To see this in Ruby, take the line you are using start_with?

and run .unpack('C*')

. This will return an array of numbers between 0

and 255

, representing the integer values โ€‹โ€‹of each byte in the string. Normal printable ASCII characters are only suitable for 126

. Any number higher than this will be the key to hiding an unprintable character in your string.



UPDATE

In this particular case, it turned out that using this diagnostic method showed that there were indeed extra bytes at the beginning of the line. They appeared at the beginning of the array as [239, 187, 191, ...]

, the string equivalent of which is equal to "\xEF\xBB\xBF"

or encoded UTF-8 encoded ZERO WIDTH NO-BREAK SPACE, which is inserted as a byte order mark at the beginning of the file by some text editors.

+4


source







All Articles