3

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

enter image description here

Thanks!

Stefan
  • 109,145
  • 14
  • 143
  • 218
user3903214
  • 203
  • 1
  • 9

1 Answers1

4

Your string may contain a hidden unicode character.

If so, the string starts with that character, not with #, which is why you're getting false.

To see it in Ruby, take the string you're running start_with? on and instead run .unpack('C*'). This will return an array of numbers between 0 and 255, representing the integer values of every byte in the string. Normal printable ASCII characters only go up to 126. Any number higher than that will be a clue that there is a non-printing character hiding 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 string. They appeared at the beginning of the array as [239, 187, 191, ...], the string equivalent of which is "\xEF\xBB\xBF" or the UTF-8 codepoint ZERO WIDTH NO-BREAK SPACE, which is inserted as a byte-order mark at the beginning of a file by some text editors.

user513951
  • 12,445
  • 7
  • 65
  • 82
  • i got this. how do i interpret this? `[-17, -69, -65, 35, 104, 111, 119, 32, 116, 111, 32, 100, 111, 119, 110, 108, 111, 97, 100, 32, 109, 101, 109, 116, 101, 115, 116, 32, 112, 108, 117, 115, 32, 55, 13, 10]` – user3903214 Nov 10 '14 at 08:08
  • You can open files in `r:bom|utf-8` mode to strip the BOM. – Patrick Oscity Nov 10 '14 at 08:21