logo       

1.9 inverse of String#ord: msg#02318

ruby-talk

Subject: 1.9 inverse of String#ord

Is there a simple inverse of String#ord in ruby 1.9?

This is the best I can come up with:

>> cp = "Å".ord
=> 322
>> [cp].pack("N").force_encoding("UTF-32BE").encode!("UTF-8")
=> "Å"

Note that Integer#chr only works up to 255.
--
Posted via http://www.ruby-forum.com/.

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise