Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在解析文件时,我想查找一行,然后从那里开始解析:
inFile.each_line do |line| if line == 'User E' #start parsing next line end end
你如何建议我做这种事情?我应该回到正常循环吗?如果我使用break,有没有办法让迭代器的迭代计数保持不变?
break
我会去:
string = "I want to parse from here to here" index = string.index(from) string[index,-1].each_line do |l| parse end
这种方式应该比使用 split 或为每一行添加测试更快。
如果您的文件很大,您可能希望分块获取它。