Skip to content

Instantly share code, notes, and snippets.

@844196
Last active August 29, 2015 14:22
Show Gist options
  • Save 844196/25ced32640ab904ab0b2 to your computer and use it in GitHub Desktop.
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
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') #=> 'に', 'ゃ', 'ん', 'ぱ', 'す', 'ー'
}
#=> にゃんぱすー
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
@844196
Copy link
Author

844196 commented Jun 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment