Last active
August 29, 2015 14:22
-
-
Save 844196/25ced32640ab904ab0b2 to your computer and use it in GitHub Desktop.
\u3046\u3061\u3082\u30aa\u30ea\u30b8\u30ca\u30eb\u3042\u3084\u3068\u308a\u3067\u304d\u305f\u3093
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts '\u306b\u3083\u3093\u3071\u3059\u30fc' | |
.gsub(/\\u([0-9a-fA-F]{1,4})/) { #=> '306b', '3083', '3093', '3071', '3059', '30fc' | |
[$1.hex] #=> '12395', '12419', '12435', '12401', '12377', '12540' | |
.pack('U') #=> 'に', 'ゃ', 'ん', 'ぱ', 'す', 'ー' | |
} | |
#=> にゃんぱすー |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts 'にゃんぱすー' | |
.unpack('U*') #=> [12395, 12419, 12435, 12401, 12377, 12540] | |
.map {|cp| '\u' + cp.to_s(16) } #=> ["\\u306b", "\\u3083", "\\u3093", "\\u3071", "\\u3059", "\\u30fc"] | |
.join #=> "\\u306b\\u3083\\u3093\\u3071\\u3059\\u30fc" | |
#=> \u306b\u3083\u3093\u3071\u3059\u30fc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: \u306b\u3083\u3093\u3071\u3059\u30fc by keepoff07 - GitHub Gist