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

filename = "note.adoc"
t( endswith( filename, ".adoc" ), true )
t( endswith( filename, ".txt" ), false )

t()

Inspired by