[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: the most optimal string "trim" implementation
- From: Shmuel Zeigerman <shmuz@...>
- Date: Sun, 27 Dec 2009 01:31:19 +0200
David Manura wrote:
Here's the latest proposed
local match = string.match
return match(s,'^()%s*$') and '' or match(s,'^%s*(.*%S)')
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).
local from = s:find("%S")
return from and s:match(".*%S", from) or ""