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( "taptest" )
local ltrim = require( "ltrim" )

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

t()

See also