How change charset of file

H

hirogeek

Hi,

I try to create file with utf-8 charset.


If I do

File.open("test.xml", 'w:utf-8') { |f| f.write('<?xml version="1.0" encoding="UTF-8"?>') }

file -I test.xml -> test.xml: application/xml; charset=us-ascii

and I do

File.open("test.xml", 'w:utf-8') { |f| f.write('<?xml version="1.0" encoding="UTF-8" é?>') }

I add an utf-8 char (é)

file -I test.xml -> test.xml: application/xml; charset=utf-8

Ruby seem to be adaptative. But I would have alwayse charset utf-8. Can we do this ?

I use ruby 2.1.1
 
Q

Quintus

Hi,
Hi,

I try to create file with utf-8 charset.

What you’re seeing is that UTF-8 is in fact 100% compatible with
US-ASCII for all 7-bit-ASCII characters. There’s just no difference
between the two encodings until you actually...
I add an utf-8 char (é)

....add a non-ASCII character to your string.

Vale,
Marvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top