From: Jim McKerchar Date: 2008-12-10T23:44:38+09:00 Subject: Re: chars method Thanks James. I hadn't thought of that :) James Gray wrote: > On Dec 10, 2008, at 7:44 AM, Jim McKerchar wrote: > >> George. If you're not yet ready to move up to a newer version of >> Ruby, you could always add a chars method to String..... >> >> class String >> def chars >> self.split( "" ) >> end >> end >> >> "abcde".chars >> => ["a", "b", "c", "d", "e"] > > Note that your method would probably be better named as bytes() > instead of chars(): > > $ ruby -e 'p "r�sum�".split("")' > ["r", "\303", "\251", "s", "u", "m", "\303", "\251"] > > If you wanted to support UTF-8 characters, you could replace split("") > with scan(/./mu): > > $ ruby -KUe 'p "r�sum�".scan(/./mu)' > ["r", "�", "s", "u", "m", "�"] > > I've written about this on my blog quite a bit, if you are interested: > > http://blog.grayproductions.net/articles/understanding_m17n > > James Edward Gray II > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - http://www.avg.com > Version: 8.0.176 / Virus Database: 270.9.16/1841 - Release Date: 10/12/2008 09:30 > >