Given a string string
, what is the fastest/most-efficient way to count lines therein? Will accept best answers for any flavour of Rebol. I\'ve been working unde
Here's the best simple non-parse
version I can think of:
count-lines: function [text [string!]] [
i: 1
find-all text newline [++ i]
i
]
It uses function
and ++
from more recent versions of Rebol, and find-all
from either R3 or R2/Forward. You could look at the source of find-all
and inline what you find and optimize, but situations like this are exactly what we wrote find-all
for, so why not use it?