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

What is ':find()' used for?

Asked by 10 years ago

I've seen it used in 1 or 2 scripts, but I do not know what it is used for, nor do I know how to use it, I do know it is used to find a string, but I am not too sure.

0
Not sure... It might be a varied form of :findFirstChild(), but are you sure it wasn't a function inside their script? systematicaddict 295 — 10y

3 answers

Log in to vote
2
Answered by
Lacryma 548 Moderation Voter
10 years ago

You are correct, it is used to find a string of characters within a string and it returns the indexes.

str = "hi u ok man"

print(str:find("ok")) --> 6,7
Ad
Log in to vote
1
Answered by 10 years ago

You can use it to find the location of a string, inside a string. Here's an example:

local mystring = "Hello, world"
print(mystring:sub(mystring:find("Hello"))) -- Hello

mystring:find("Hello") returns 1 5 (not 15!) because Hello in the string mystring is between the 1st and 5th character positions.

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

It's the shorthand for string.find, like the shorthand for string.lower() is :lower().

Answer this question