lua-users home
lua-l archive

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


David Manura wrote:
Here's the latest proposed
version:

   local match = string.match
   function trim(s)
     return match(s,'^()%s*$') and '' or match(s,'^%s*(.*%S)')
   end

Here's my latest favorite. In a few tests I did, it slightly outperformed your variant, except for the all-space strings, where it performed worse (which I don't understand why).

function trim(s)
  local from = s:find("%S")
  return from and s:match(".*%S", from) or ""
end



--
Shmuel