lua-users home
lua-l archive

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


On Fri, 2009-12-25 at 00:25 -0500, David Manura wrote:
> 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

I can assure you that the following is more optimal:
	
	local string_match = string.match
	local function trim(s)
		return string_match(s, "^%s*(.*%S)%s*$") or ""
	end