Sorry, what is this supposed to do? It looks like you are wanting to use
glob patterns in your line delimiter? I suspect this is not the best
approach to solving this problem, could you give an example of the input
file, and what values you are wanting your variable "line" to take?
···
On Fri, Mar 11, 2011 at 8:36 AM, vahag vardanyan <vahagvardanyan@gmail.com>wrote:
how can I do it in ruby
my example is
while(line=f.gets(sep="class#{i} here will be any text "))
...
...
i+=1
end
It still needs to be better defined, his/her example delimiter is "class#{i}
here will be any text ", so it isn't correct to assume the delimiter
ends after the first digit. We really need more data, to understand what
he/she actually wants to have happen, if you throw a splat in there, it will
eat up the rest of the string.
Another issue that could arise is if input is a large file, it could be too
big to fit into memory, in this case, you might be able to use strscan from
the standard library, or maybe have to find a gem to handle it, not sure, OP
needs to give more information.
···
On Fri, Mar 11, 2011 at 9:12 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:
str = "class#1 hello world class#2 goodbye class#3 hi"
arr = str.split(/ (class\#\d) /xms)
p arr
arr.shift
while arr.length > 0
puts arr.slice!(0,2).join
end
--output:--
["", "class#1", " hello world ", "class#2", " goodbye ", "class#3", "
hi"]
class#1 hello world
class#2 goodbye
class#3 hi