How to print unicode character U-1F4A9 'pile of poo' emoji 💩

两盒软妹~` 提交于 2019-12-09 05:14:02

问题


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.

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)


回答1:


Unicode code points with more than four hex digits must be enclosed in curly braces:

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:

puts "💩"
# => 💩


来源:https://stackoverflow.com/questions/30626924/how-to-print-unicode-character-u-1f4a9-pile-of-poo-emoji

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!