Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get utf8 characters from File#path

File#path is giving me Latin-1 characters -- is there a way to get it to give me utf8 characters, or should I just convert what it returns? If so, what's the best/easiest way to convert?

elaboration

So, I know I can do this:

Iconv.new('UTF-8','LATIN1').iconv(File.basename(file.path))

But I'm wondering if there is a more elegant way to tell File to give me utf8 to begin with.

This is especially important because for some reason I get back a different charset on different systems. On my OS X dev machine, it looks like I get back utf8. On my linux server, latin-1.

like image 669
John Bachir Avatar asked Jan 21 '26 18:01

John Bachir


1 Answers

Use a magic comment in a first line of your document:

#encoding: UTF-8
like image 130
Nick Nizovtsev Avatar answered Jan 24 '26 10:01

Nick Nizovtsev