lua-users home
lua-l archive

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


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