3

I was wondering if there is a way to get the character for a given UTF-8 code ?

E.g.:

1103 = > "я"(russian letter)
falsetru
  • 357,413
  • 63
  • 732
  • 636
user2128702
  • 2,059
  • 2
  • 29
  • 74

2 Answers2

4

Using Array#pack with U directive (UTF-8 character):

[1103].pack('U')
# => "я"
falsetru
  • 357,413
  • 63
  • 732
  • 636
3

Another approach is "\u{hex}", e.g. "\u{4355}". This syntax accepts only hex numbers, not decimal. Syntax U+184B is the most commonly used one for referencing Unicode characters.

Nowaker
  • 12,154
  • 4
  • 56
  • 62