Check if string starts from substring

How can I check if string starts from another substring? Like in python you can do

if "string":startswith("str") then

and it will return true but how to do it in roblox lua?

if (“string”):find("^str") then

^ at the very start means it must start with that, it’s not enough if it’s somewhere in the middle

3 Likes
local startswith = 'somestring'
if str:sub(1,#startswith) == startswith then

end

or

local startswith = 'somestring2'
if str:find(startswith) == 1 then

end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.