Craig Demyanovich
10/20/2008 3:04:00 PM
[Note: parts of this message were removed to make it a legal post.]
I thought String#split with a regex might do it, but I'm not sure why it
returns an array with empty strings in it. So I tried String#scan. It works,
but since we're grouping into runs of eight characters, it returns an array
of arrays of results. No problem, we can just use Array#flatten to take care
of that. Here's IRB output showing the approaches:
>> '0000000N0000000N0000000N0000000N'.split(/(\w{8})/)
=> ["", "0000000N", "", "0000000N", "", "0000000N", "", "0000000N"]
>> '0000000N0000000N0000000N0000000N'.scan(/(\w{8})/)
=> [["0000000N"], ["0000000N"], ["0000000N"], ["0000000N"]]
>> '0000000N0000000N0000000N0000000N'.scan(/(\w{8})/).flatten
=> ["0000000N", "0000000N", "0000000N", "0000000N"]
Regards,
Craig