lua-users home
lua-l archive

Re: string.lines (a suggestion)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 27-Jul-04, at 6:32 PM, Asko Kauppi wrote:
It probably does the job, but -honestly- I've never even used 'gfind' before.
string.gfind is really handy.
As an example, the question of iterating over a string which was floating around earlier could probably best be handled with:
for ch in string.gfind(str, ".") do
 -- handle a character
end
. The point is, Lua should be intuitive and straightforward, and "for line in string.lines(str)" was the first thing I'd try just by guessing.
So put this in your startup:
function string.lines(str) return string.gfind(str, "[^\n]+") end
:)
Some time ago I put some other string-slinging examples, several taken from PIL, on the wiki: http://lua-users.org/wiki/StringRecipes

AltStyle によって変換されたページ (->オリジナル) /