Module:string/startswith

From Linguifex
< Module:string
Revision as of 09:16, 28 June 2025 by Sware (talk | contribs) (Created page with "local sub = string.sub --[==[ Returns {true} if the string {str} starts with the string {val}, or {false} if not. The optional indices {i} and {j} can be used to check a substring of {str}. Note that {val} is a string literal, not a Lua pattern.]==] return function(str, val, i, j) return sub(i == nil and j == nil and str or sub(str, i, j), 1, #val) == val end")
Jump to navigation Jump to search

Documentation for this module may be created at Module:string/startswith/doc

local sub = string.sub

--[==[
Returns {true} if the string {str} starts with the string {val}, or {false} if not. The optional indices {i} and {j} can be used to check a substring of {str}.

Note that {val} is a string literal, not a Lua pattern.]==]
return function(str, val, i, j)
	return sub(i == nil and j == nil and str or sub(str, i, j), 1, #val) == val
end