From: Dossy Date: 2002-07-08T06:46:41+09:00 Subject: Re: is there a better string.each? On 2002.07.08, Nobuyoshi Nakada wrote: > Hi, > > At Sun, 7 Jul 2002 22:43:57 +0900, > Dossy wrote: > > > 'foo'.split '' > > > # ["f", "o", "o"] > > > > > > anywas; it would probably pass the chars to the black *and* return an array. > > > > This fails when the string is encoded in a multi-byte encoding (such > > as Japanese, Chinese, etc.) unless String#split is modified in the > > core to split on actual logical "characters" (which might be one or > > more bytes, depending on the encoding). > > String#split is multi-byte aware. > > $KCODE="EUC" > a = "\xa1\xa1\xa1\xa2".split("") > $KCODE="NONE" > p a #=> ["\241\241", "\241\242"] > > Or > a = "\xa1\xa1\xa1\xa2".split(//e) > p a #=> ["\241\241", "\241\242"] Oh, hey, wow! Who snuck this in and where was it documented? :-) It works on 1.6.7 (2002-03-19), cool! -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)