Dogweather
Dogweather

Reputation: 16779

How do I see exactly what characters are in a string?

Check out the weird behavior I'm getting with two strings. I suspect of course, that the space isn't really a space. How do I investigate this?

enter image description here

Upvotes: 2

Views: 95

Answers (1)

Gareth
Gareth

Reputation: 138032

Try something like:

1.9.2p290> "foo bar".bytes.to_a # the space is a nonbreaking-space
 => [102, 111, 111, 194, 160, 98, 97, 114] 

or if hex codes for characters are your thing:

1.9.2p290> "foo bar".chars.map { |c| c.unpack "H*" } # same nonbreaking-space
 => [["66"], ["6f"], ["6f"], ["c2a0"], ["62"], ["61"], ["72"]] 

Upvotes: 5

Related Questions