ltrim

function ltrim( str ) --> nstr

Description

The ltrim function returns the string stripped of whitespaces from the left side.

Parameters

str

The string that should be trimmed.

Return Values

nstr

A trimmed version of the assigned parameter string.

Code

--ZFUNC-ltrim-v1
local function ltrim( str ) --> nstr
   local n = str:find( "%S" )
   return n and str:sub( n ) or ""
end

return ltrim

Examples

local t = require( "tapered" )
local ltrim = require( "ltrim" )

t.is( "", ltrim( "" ) )
t.is( "", ltrim( " " ) )
t.is( "", ltrim( "  " ) )
t.is( "a", ltrim( "a" ) )
t.is( "a", ltrim( " a" ) )
t.is( "a ", ltrim( "a " ) )
t.is( "a ", ltrim( " a " ) )
t.is( "a  ", ltrim( "  a  " ) )
t.is( "ab cd ", ltrim( " ab cd " ) )
t.is( "a\00b \r\t\n\f\v", ltrim( " \t\r\n\f\va\00b \r\t\n\f\v" ) )

t.done()

See also