Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is ':find()' used for?

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.

1 comment

0

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

3 answers

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

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.