From: James Gray Date: 2008-10-20T23:40:25+09:00 Subject: Re: Way to split a string based on fixed length? On Oct 20, 2008, at 9:34 AM, Wayne Molina wrote: > This is probably a newb question but I can't seem to figure it out. I > have a string I'm trying to parse, that is done via a fixed length > format - it needs to be split on every 8th character in order for me > to > get a proper array list of it so I can do some additional operations > on > it. > > The string is something like this: '0000000N0000000N0000000N0000000N' > and I need it to be an array containing something like: ['0000000N', > '0000000N', '0000000N', '0000000N']. > > Is there a ruby method I can use to split the single string into > groups > of x number of characters, when there is no delimiter? Sure, you can use a regular expression for this: >> "0000000N0000000N0000000N0000000N".scan(/.{1,8}/m) => ["0000000N", "0000000N", "0000000N", "0000000N"] James Edward Gray II