lua-users wiki: String Trim



function trim1(s)
   return (s:gsub("^%s*(.-)%s*$", "%1"))
end


function trim2(s)
   return s:match "^%s*(.-)%s*$"
end


function trim3(s)
   return s:gsub("^%s+", ""):gsub("%s+$", "")
end


function trim4(s)
   return s:match"^%s*(.*)":match"(.-)%s*$"
end


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


function trim6(s)
   return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end








local match = string.match
function trim7(s)
 ...

Read the entire article at the source link…

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*