From: Brian Candler Date: 2010-03-03T20:43:42+09:00 Subject: Re: How do I set the encoding on a regexp ? Roger Pack wrote: > re: string1 + string2 + string3 actually working without fear... > > One thing that might help would be to set the default encoding, then all > three strings would (might ?) have the same encoding (?) That depends where the strings came from. If they were returned by a library function (either Ruby core or 3rd party) you won't know what encoding they have unless it is documented what the encoding is or how it is chosen, and it almost never is. Equally, if you are writing a library for use by other people, then you really should not touch global state such as Encoding.default_external. So you are left with Ruby guessing encodings and forcing them if it guesses wrongly, e.g. $ ruby19 -e 'puts %x{cat /bin/sh}.encoding' UTF-8 Of course, if you're saying that your application handles all strings in the same encoding, then this whole business of tagging every *individual* string object with its own encoding is a waste of time and effort, and is just something which you have to fight against. But we're flogging a dead horse here. I hate this stuff; other people seem to love it. -- Posted via http://www.ruby-forum.com/.