开发者

Output the euro sign in a ruby script

I'm currently trying to output the euro symbol开发者_JAVA技巧 through a simple ruby script that I made but I keep getting "?" whenever I try.

I'm currently using puts "\244".

Any thoughts?

btw. I'm using ruby 1.9.2 p180


You need to add a "magic comment" at the top of your script like this:

# encoding: UTF-8

puts "€"

... assuming that you want to use UTF-8 to allow for double-byte characters. You can then use the Euro symbol directly.

You can read more about Ruby 1.9 string encoding and magic comments here:

http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜