I need to encode/convert a Unicode string to its escaped form, with backslashes. Anybody know how?
If you have Rails kicking around you can use the JSON encoder for this:
require 'active_support' x = ActiveSupport::JSON.encode('µ') # x is now "\u00b5"
The usual non-Rails JSON encoder doesn't "\u"-ify Unicode.