endswith

function endswith( str, suffix ) --> res

Description

Checks if str ends with suffix.

Parameters

str

The string that should be checked.

suffix

The string to search for.

Return Values

res

Is true if the string ends with suffix, otherwise false.

Code

--ZFUNC-endswith-v1
local function endswith( str, suffix ) --> res
   return string.sub( str, -string.len( suffix ) ) == suffix
end

return endswith

Examples

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

filename = "note.adoc"
t.ok( endswith( filename, ".adoc" ) )
t.nok( endswith( filename, ".txt" ) )

t.done()

Inspired by