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

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

t()

See also