I'm using unicode in a Rails app and there are some cases where I'd like
to use escape sequences for characters instead of the literal
characters.
Case in point is Horizontal Ellipsis, hex 2026. I thought this would be
\x2026, but Ruby only takes the first two characters following \x into
account. Is there some way to make Ruby cooperate?
Michael
···
--
Michael Schuerig The Fifth Rider of the Apocalypse
mailto:michael@schuerig.de is a programmer.
http://www.schuerig.de/michael/
Ruby does not yet support Unicode literals in any way. You will need
to use the proper UTF-8 encoding bytes as a string. If you can work
with IConv or something, you might be able to use \x20\x26.
-austin
···
On 6/30/05, Michael Schuerig <michael@schuerig.de> wrote:
I'm using unicode in a Rails app and there are some cases where I'd like
to use escape sequences for characters instead of the literal
characters.
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
You need to encode it into UTF8 or similar:
$ ruby -e 'puts "\342\200\246"'
…
$
···
On 30 Jun 2005, at 13:15, Michael Schuerig wrote:
I'm using unicode in a Rails app and there are some cases where I'd like
to use escape sequences for characters instead of the literal
characters.
Case in point is Horizontal Ellipsis, hex 2026. I thought this would be
\x2026, but Ruby only takes the first two characters following \x into
account. Is there some way to make Ruby cooperate?
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
Michael Schuerig wrote:
Thanks! Somehow I didn't expect this to work. Good that it does. I'm using hex "\xe2\x80\xa6" instead as that's what the nice (unixoid) unicode command line tool shows, among other things.
module Kernel
def u( str )
str.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
end
end
>> u"U+2026"
=> "\342\200\246"
>> "\xe2\x80\xa6"
=> "\342\200\246"
_why