Ruby: Is there a way to split a string only with the first x occurrencies?
Posted
by zxcvbnm
on Stack Overflow
See other posts from Stack Overflow
or by zxcvbnm
Published on 2010-04-04T17:47:16Z
Indexed on
2010/04/04
17:53 UTC
Read the original article
Hit count: 280
For example, suppose I have this:
001, "john doe", "male", 37, "programmer", "likes dogs, women, and is lazy"
The problem is that the line is only supposed to have 6 fields. But if I separate it with split I get more, due to the comma being used improperly to separate the fields.
Right now I'm splitting everything, then when I get to the 5-th index onward I concatenate all the strings. But I was wondering if there was a split(",",6) or something along these lines.
© Stack Overflow or respective owner