Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
utf8エンコーディングを使用して、私は知っています
a = "\u20ac" #=> "€"
とにかく、このプロセスを逆にして文字列€から「\u20ac」を取得することはあるのでしょうか?
お気に入り
a.get_encoding_method #=> "\u20ac"
escaped = '\u' + a.unpack('U')[0].to_s(16)
試してみてください'\u%x' % a.ord。(リテラルのバックスラッシュと を含む文字列で終わりたいと仮定しますu)。
'\u%x' % a.ord
u
pack と unpack を使用して、前後に変換できます。例えば:
'€'.unpack('U*') => [8364] [8364].pack('U*') => "€"