Subheader

Lazy Programmer's Blog

Pages

Showing posts with label char. Show all posts
Showing posts with label char. Show all posts

Saturday, March 26, 2016

How to get character's unicode value in Ruby

The solution is to use .ord.to_s(16)

Examples:
'♥'.ord.to_s(16) = 2665
'$'.ord.to_s(16) = 24
'€'.ord.to_s(16) = 20ac
'a'.ord.to_s(16) = 61

Getting unicode value of string:
'my string'.each_char.map{|c| c.ord.to_s(16)}.join