I have wrote this following code to output aphostrophe (code 39 for utf-8):

test_utf8.rb:
puts "It\39s a wonderful life"

then ran it using:
ruby test_utf8.rb > utf8.txt

While opening in gedit it shows a box corresponding to \39. While opening in open office, it asks which encoding and after selecting utf-8 it shows it as

It#9s a wonderful life.

Why is this happening how to overcome this problem?

Thanks

Recommended Answers

All 2 Replies

You could just do either of these

yourString = "This is Kyle's string" 
yourOtherString = 'This is Kyle\'s string'

It is not an elegant solution. It is a hack. The problem was that the number after '\' should be an oct or a hex. So I had to convert 39 to oct/hex to get over this problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.