This only returns “1” no matter how hard i try? (I can’t find a second argument.)
Otherwise:
local str = "rbxassetid://607948062"
local s, f = string.find(str, "rbx://") or string.find(str, "rbxassetid://")
local new = string.split(s, "%p")
print(new)
print(new[1], new[2])
local str = "rbxassetid://607948062"
local s, f = string.find(str, "rbx://", 1, true)
if not f then
s, f = string.find(str, "rbxassetid://", 1, true)
end
print(s, f)
Of course it wont return two strings, returns the indices of str where the occurrence starts and ends
And f here will always be nil no matter what you do, that’s because it’s assigning the first value to s and ignoring f
It’s the same as doing
local str = "rbxassetid://607948062"
local s = string.find(str, "rbx://") or string.find(str, "rbxassetid://")
local f = nil
print(s, f) -- f will always be nil
So the best way I found is this:
It doesn’t look elegante but it gets the job done.
That’s not a solution, the whole point of using or is to go to the second option if the first one is nil, you just switched them cause you know what str is.
Well then u shudn’t stress over this so much, there is a way to do it rite? Its such a simple issue, so u shudn’t neglect it over a matter as silly as clean code.
local str = "Nerbzzz"
-------------^^^^^^^
-------------1234567
local startIndex, endIndex = string.find(str, "zzz")
print(startIndex) -- This prints 5
print(endIndex) -- This prints 7
Most languages return -1 if a requested item is not found, but since Lua returns nil on a failed search, that method is probably the most efficient way to do it.