This is probably obvious in the docs and I'm just missing it, but here
goes: So, I see there is str.each_codepoint, which I want to use in a
function to convert Unicode Strings to a list of Unicode code points.
But what can I do if I have a list of Unicode code points and want to
convert them back into a String?
This is probably obvious in the docs and I'm just missing it, but here
goes: So, I see there is str.each_codepoint, which I want to use in a
function to convert Unicode Strings to a list of Unicode code points.
But what can I do if I have a list of Unicode code points and want to
convert them back into a String?
This is probably obvious in the docs and I'm just missing it, but here
goes: So, I see there is str.each_codepoint, which I want to use in a
function to convert Unicode Strings to a list of Unicode code points.
But what can I do if I have a list of Unicode code points and want to
convert them back into a String?
#encoding: UTF-8 #That comment tells ruby to treat string literals in my source code,
like #the one below, as utf-8 encoded.
str = "\xE2\x82\xAC\xE2\x82\xAC"
codes = str.each_codepoint.to_a
p codes
puts codes.map {|code| code.chr(Encoding::UTF_8) }.join(" ")
--output:--
[8364, 8364]
€ €
(You should see two euro symbols as the last line of output.)
I don't know where you are getting your string, but you can always do
this: