I am trying to print a unicode character in Ruby, specifically the pile of poo. It has a unicode value of U-1F4A9. But when I try to print "\u1F4A9" to the output or a file, I see nothing.
我正在尝试用Ruby打印unicode字符,特别是一堆便便。它的unicode值是U-1F4A9。但是当我尝试将“\u1F4A9”打印到输出或文件时,我什么也看不到。
Do I need to print to a specific type of file to see the pile of poo? If so, what type of file? Is there any way to print this to the common output? (I'm using Rubymine)
我需要打印一个特定类型的文件才能看到一堆便便吗?如果有,是什么类型的文件?有没有办法把它打印到公共输出?(我使用Rubymine)
1 个解决方案
#1
27
Unicode code points with more than four hex digits must be enclosed in curly braces:
Unicode码点超过四个十六进制数字必须包含在大括号内:
puts "\u{1f4a9}"
# => ????
This is pretty poorly documented, so don't feel bad about not figuring it out. A nice thing about the curly brace syntax is that you can embed multiple code points separated by spaces:
这是一个很糟糕的文档,所以不要因为没有弄明白而感觉不好。花括号语法的一个好处是,可以嵌入由空格分隔的多个代码点:
puts "\u{1f4a9 1f60e}"
# => ????????
Of course, since Ruby 2.0, UTF-8 has been the default encoding, so you can always just put the emoji directly into your source:
当然,自从Ruby 2.0以来,UTF-8一直是默认的编码方式,所以你可以直接将表情符号输入你的源文件:
puts "????"
# => ????
#1
27
Unicode code points with more than four hex digits must be enclosed in curly braces:
Unicode码点超过四个十六进制数字必须包含在大括号内:
puts "\u{1f4a9}"
# => ????
This is pretty poorly documented, so don't feel bad about not figuring it out. A nice thing about the curly brace syntax is that you can embed multiple code points separated by spaces:
这是一个很糟糕的文档,所以不要因为没有弄明白而感觉不好。花括号语法的一个好处是,可以嵌入由空格分隔的多个代码点:
puts "\u{1f4a9 1f60e}"
# => ????????
Of course, since Ruby 2.0, UTF-8 has been the default encoding, so you can always just put the emoji directly into your source:
当然,自从Ruby 2.0以来,UTF-8一直是默认的编码方式,所以你可以直接将表情符号输入你的源文件:
puts "????"
# => ????