Skip to content

Instantly share code, notes, and snippets.

@clockworkpc
Forked from O-I/get_character.rb
Last active April 27, 2017 22:19
Show Gist options
  • Save clockworkpc/079184e48b62d2a9e85553ee6810bee2 to your computer and use it in GitHub Desktop.
Save clockworkpc/079184e48b62d2a9e85553ee6810bee2 to your computer and use it in GitHub Desktop.
Ruby Character to Unicode Converter
def get_character(hexnum)
char = ''
char << hexnum.to_i(16)
end
def get_unicode(char)
(0..55295).each do |pos|
# (0..109976).each do |pos|
chr = ""
chr << pos
if chr == char
puts "This is the unicode of #{char}: #{pos.to_s(16)}"
end
end
end

Ruby Character to Unicode Converter

(and vice versa)

Forked from the original Gist script. I had to change the range from 109_967 in order to make it work.

Original description below.

I 'accidentally' created this while trying to make a string representation of the first million digits of the Champernowne constant. I thought it was pretty nifty, so I'm sharing.

Ever needed to find the Unicode value of some crazy-cool character like, say, ∀? Just

puts get_unicode('∀')

and you'll find its hex value is:

2200

Or if you've always been itching to know what Unicode character is represented by hex value 2752,

puts get_character('2752')

to find out. Go ahead — play with it — you know you want to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment