lastchar

function lastchar( str ) --> charstr

Description

Returns the last char in a string. If the string is empty returns the function an empty string.

Parameters

str

The source string.

Return Values

charstr

The last char value.

Code

--ZFUNC-lastchar-v1
local function lastchar( str ) --> charstr
   return string.sub( str, #str )
end

return lastchar

Examples

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

t.is( "c", lastchar( "abc" ) )
t.is( "", lastchar( "" ) )

t.done()

See also