Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local startsWith = function(stringValue, searchValue, position)
- if stringValue and searchValue then
- if position then
- return string.sub(string.sub(stringValue, position + 1), 1, #searchValue) == searchValue
- else
- return string.sub(stringValue, 1, #searchValue) == searchValue
- end
- else
- return false
- end
- end
- -- example
- -- code | expected output
- startsWith("testing oof", "testing") -- true
- startsWith("testing oof", "oof", 8) -- true
- --
- startsWith() -- false
- startsWith("testing oof") -- false
- startsWith("testing oof", "oof") -- false
- startsWith("testing oof", "oof", 10) -- false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement