Trim whitespace from string (LUA)
Simple implementation to trim leading and trailing whitespace from a string in LUA
Similar To
- PHP: trim()
- Python: strip()
- Javascript: trim()
Details
- Language: LUA
Snippet
function trim(s)
return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end
Usage Example
local a = ' abcde fg '
print( a..'END' )
print(trim(a)..'END')