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

str = "abcdef"
t( startswith( str, "abc" ), true )
t( startswith( str, "def" ), false )

t()

Inspired by

See also