Hi -- On Sun, 12 Oct 2003, Mike Campbell wrote: > I have a line of text output in columnar form; what's the best way to split it > into its requisite parts? > > Say I have lines of > > aaaaabbcccccddeee > > I can do something like: > > md = /(.....)(..)(.....)(..)(...)/.match(line); # seems klugy somehow > > > Thoughts? I think the main disadvantage of the above is that it's a bit awkward to write into a method. So you might want to do something like: class String def columnize(*sizes) str = dup sizes.map {|s| str.slice!(0...s)} end end p "aaaabbbbcccddddd".columnize(4,4,3,5) # ["aaaa", "bbbb", "ccc", "ddddd"] David -- David Alan Black home: dblack / superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav