[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: the most optimal string "trim" implementation
- From: David Manura <dm.lua@...>
- Date: Fri, 25 Dec 2009 00:25:36 -0500
I contend [1] that the most optimal way to implement a string "trim"
function is basically this:
function trim(s)
return s:match'^%s*(.*%S)%s*$' or ''
end
at least when sticking to Lua pattern matching operations. You can
also localize the match function, but the added benefit is not huge.
I would recommend the above version for Penlight and other standard
libraries.
[1] http://lua-users.org/wiki/StringTrim