Check if String starts with "Models/Player"

How would I check if a string starts with “Models/Player”?

[lua]
if (string.sub(string here, 1, 13) == “models/player”) then
– Blah blah blah
end;
[/lua]

If you want to check if it starts with it you should use string.Left.
[lua]
if string.Left(string here,string.len(stringwecheck)) == stringwecheck then

end
[/lua]

You shouldn’t, string.left is just a wrapper for string.sub, also if the string length is constant there is no need to get the length.

also, if you mean it start either with models or player, you can easly change it into


if string.sub(1,6) == "models" or string.sub(1,6) == "player" then
 -- execute code
end

Yet, if youre going to sue these kind of code a lot, you can simply make a function that works like this:


function either(s_table,stringc)
for _,v in pairs(s_table) do
 if string.sub(1,string.len(v)) == v then
return true, v
end
end
end

where s_table is a table holding the string ({“models”,“player”}) and stringc is the checked string

the function returns two value - the first holding a boolean value - whether the string was changed or not and the second saying which string did it hold

Also - this post is useless if you meant it starts with “models/player” and not “models or player”