From: Robert Dober Date: 2006-03-21T01:29:05+09:00 Subject: Re: iterate chars in a string ------=_Part_4029_5262734.1142872126962 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello World "I am puzzled".each_byte do |b| puts "%c" % b ;end Cheers Robert On 3/20/06, James Edward Gray II wrote: > > On Mar 20, 2006, at 3:38 AM, Robert Klemme wrote: > > > Kev Jackson wrote: > >> Robert Klemme wrote: > >>> Lyndon Samson wrote: > >>> > >>>> a=3D"123" > >>>> > >>>> 0.upto(a.length) { |i| puts a[i..i] } > >>> > >>> > >>> Alternatively: > >>> > >>> a.length.times {|i| puts a[i].chr} > >>> > >>> Many roads to Rome... > >>> > >>> robert > >>> > >> or even > >> a.scan(/./) { |c| p c } > > > > We had that already: your version ignores newlines. :-) > > >> require "jcode" > =3D> true > >> "Hello\nWorld!".each_char { |chr| p chr } > "H" > "e" > "l" > "l" > "o" > "\n" > "W" > "o" > "r" > "l" > "d" > "!" > =3D> "Hello\nWorld!" > > James Edward Gray II > > -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_4029_5262734.1142872126962--