lua-users home
lua-l archive

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


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

The function below is faster, especially when there's a great quantity of trailing space.

  function trim(s)
    return s:match'^%s*(.*%S)' or ''
  end

--
Shmuel