Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using string.find and others like it?

Asked by 4 years ago

I'm trying to find a string within v's Name and then return that string that was found but I don't know how to as I'm pretty sure string.find does not return a copy of the string.

local name = string.find(v.Name, ele[i])
0
can you show a full script please starmaq 1290 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Similar to string.match(), instead of returning the string, it returns the number position of the string, similar of the 2nd parameter to string.sub(). As in if I used.

local s1 = 'Potato'
local s2 = 'tat'
local s3,s4 = string.find(s1,s2) -- string, substring
print(s3 , s4)

Instead of printing, a string, s3 would print 3, because that's where the function found the beginning of the smaller substring. s4 would print 5 because that's where the substring ended. Both s3 and s4 could return nil if the string does not contain a substring.

Ad

Answer this question