From: William James Date: 2005-10-14T02:21:54+09:00 Subject: Re: Iterate over md Array (the Ruby way) David A. Black wrote: > Hi -- > > On Thu, 13 Oct 2005, Peter v. N. wrote: > > > Yes, I admit that I was not very clear > > (English's not my mother tongue.. ;-) ): > > > > An input text file (@source) looks like this: > > > > 0000022340 > > 0023457000 > > 0000000110 > > 0008000000 > > 0000090000 > > 0000330000 > > 0000000730 > > 0664000000 > > 0034000000 > > > > or maybe: > > > > AGCTAGCT12345 > > AAA3BBBCC > > AAACC > > > > @source[i][j] = ASCII substring at this position: > > e.g.: val = @source[1][3] #-> "3" > > > > by non-convertible I mean everything that cannot be > > represented as an integer ("12345678A", "A".to_i # -> "0") > > > > Array a) yields in Array a) > > > > Array a) yields in 0000000012345 > > 0000000000000 > > 0000000000000 > > > > I managed to obtain such structures, but not by the Ruby way... > > See if this helps: > > array = < 0000022340 > 0023457000 > 0000000110 > AGCTAGCT12345 > AAA3BBBCC > AAACC > EOM > > max = array.map {|st| st.chomp.size }.max A minor point: since #split(/\n/) was used, #chomp isn't needed. > array.each {|s| s.replace(s.rjust(max,"0")).gsub!(/\D/,"0") } > puts array