From: Xavier Noria Date: 2003-10-12T17:13:40+09:00 Subject: Re: splitting a line by columns On Sunday 12 October 2003 05:50, 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 If the data is a fixed-width record String#unpack is a compact idiom, and it's usually fast as well. For instance: record = "aaaaabbcccccddeee" fields = record.unpack("a5a2a5a2a3") -- fxn