Escape sequences for unicode chars?

M

Michael Schuerig

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
 
A

Austin Ziegler

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.

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
--=20
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
 
E

Eric Hodel

I'm using unicode in a Rails app and there are some cases where I'd =20=
like
to use escape sequences for characters instead of the literal
characters.

Case in point is Horizontal Ellipsis, hex 2026. I thought this =20
would be
\x2026, but Ruby only takes the first two characters following \x into
account. Is there some way to make Ruby cooperate?

You need to encode it into UTF8 or similar:

$ ruby -e 'puts "\342\200\246"'
=85
$

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
 
M

Michael Schuerig

Eric said:
On 30 Jun 2005, at 13:15, Michael Schuerig wrote:

You need to encode it into UTF8 or similar:

$ ruby -e 'puts "\342\200\246"'
?
$

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.

Michael
 
W

why the lucky stiff

Michael said:
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
=> "\342\200\246"

_why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top