firstchar

function firstchar( str ) --> charstr

Description

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

Parameters

str

The source string.

Return Values

charstr

The first char value.

Code

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

return firstchar

Examples

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

t.is( "a", firstchar( "abc" ) )
t.is( "", firstchar( "" ) )

t.done()

See also