startswith

function startswith( str, prefix ) --> res

Description

Checks if str starts with prefix.

Parameters

str

The string that should be checked.

prefix

The string to search for.

Return Values

res

Is true if the string starts with prefix, otherwise false.

Code

--ZFUNC-startswith-v1
local function startswith( str, prefix ) --> res
   return string.sub( str, 1, string.len( prefix ) ) == prefix
end

return startswith

Examples

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

str = "abcdef"
t.ok( startswith( str, "abc" ) )
t.nok( startswith( str, "def" ) )

t.done()

Inspired by

See also