From: Austin Ziegler Date: 2007-08-26T00:51:00+09:00 Subject: Re: String#length not working properly in Ruby 1.9 On 8/25/07, Yukihiro Matsumoto wrote: > |Do I have to put a header like > | # -*- coding: utf-8 -*- > |into all my source files, or is there a command line option? > You can specify -Ku option for UTF-8 scripts, but I recommend coding > pragma, especially for library files. Can we get an alternate form for that as well? -*- is a little annoying to type; why not: # pragma-encoding: utf-8 (Done properly with callbacks, that could actually be used to give us user-created pragmas, too...) > |If I read from a file a string, it is automatically in US-ASCII encoding. > |How do I change the encoding, e.g. if I know that the file is in UTF-8? > Although it's not done yet, you can specify reading encoding for > files, e.g. > > open(path, "r:utf-8") {|f| > ... > } If I do this, though: s = File.readlines("foo") How do I tell Ruby what the encoding of the string is? s.encoding = 'utf-8'? s.encoding = 'raw'? -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca