From: Duane Morin Date: 2006-11-21T05:31:34+09:00 Subject: Split! I meant split. (Re: Why is slice ignoring my Found it -- there's a "limit" parameter that can be passed to split. If the value is non-zero, that affects whether null fields are returned as part of the result. I don't fully understand why that is (specifying -1 says to give me all of my fields regardless of how many I have, including nulls), so I wasn't exactly looking for such a thing. d Duane Morin wrote: > I wrote that entire post saying "slice" when what I meant to say was > "split". > Splitting a string into an array using a specified delimiter. > > Sorry about that! > > D > Duane Morin wrote: >> I'm not sure if this is a bug with the slice method, or if I'm just >> misunderstanding the logic behind it. If I have a string "1,2,3" that I >> slice into an array, I get 3 values. >> >> But if I have "1,2,3," with a trailing comma, I still get 3 -- even >> though I probably should have gotten 4, with 4 being an empty string. >> >> If I have "1,2,,3" then I will get 4 elements with the third one >> properly being an empty string. >> >> The trailing delimiter problem seems to repeat -- if I have "1,2,3,,," >> then I still end up with an array of just 3 elements. All of ones on >> the end are gone. >> >> Anybody know if this is the intended behavior, and if so, why? I'd >> think that if I'm saying delimit fields on this character, then it would >> be up to me to decide whether or not to keep the empties. Maybe there's >> a way to call split with a flag that says to keep the empties, I'm not >> sure. That just occurred to me, gonna go look into that. >> >> D -- Posted via http://www.ruby-forum.com/.