valid,invalid

関心を持てる事柄について

Rubyでemojiとcodepointsの変換

emoji から codepoints に変換

"👍".unpack("U*")
=> [128077]

"👍".codepoints
=> [128077]

# Convert to hexadecimal
"👍".each_codepoint.map {|n| n.to_s(16) }
=> ["1f44d"]

codepoints から emoji に変換

[128077].pack("U*")
=> "👍"

0x1f44d.chr('UTF-8')
=> "👍"

"\u{1f44d}"
=> "👍"

環境

Ruby 3.0.0