• Check if String starts with "Models/Player"
    4 replies, posted
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 [i]starts[/i] with it you should use string.Left. [lua] if string.Left(string here,string.len(stringwecheck)) == stringwecheck then ... end [/lua]
[QUOTE=_NewBee;34590129]If you want to check if it [i]starts[/i] with it you should use string.Left. [lua] if string.Left(string here,string.len(stringwecheck)) == stringwecheck then ... end [/lua][/QUOTE] 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 [CODE]if string.sub(1,6) == "models" or string.sub(1,6) == "player" then -- execute code end[/CODE] Yet, if youre going to sue these kind of code a lot, you can simply make a function that works like this: [CODE]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[/CODE]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"
Sorry, you need to Log In to post a reply to this thread.