So I noticed in this topic: Help with using values from a table with :split() and in some other places this :split method and I cant figure out what it does and how to find documentation about it. Any help?
Split is a string function, basically you use it to split your string in multiple parts with a separator, if i put a space in my separator it will be like this:
local MyString = "Hello! How was your day?"
MyString:split(" ")
Output:
{
[1] = "Hello!",
[2] = "How",
[3] = "was",
[4] = "your",
[5] = "day?"
}
Say you have a string with variables separated by commas such as a csv file
“this,is,the,string”
The :split(“,”) would return a table of the values
{“this”, “is”, “the”, “string”}
This is useful if you use the messagingservice for example since you can only pass a single string. Also useful for datastores.
Thank you. But why there is sometimes one dot and sometimes a colon?
stringhere:split(“separator here”)
string.split(“string here”, “separator here”)
Edit: I just attempted the :split and it doesn’t work. I don’t know what’s going on but string.split works
Its because one of them is a variable and the other one is using the string object
You can learn the difference between functions and instance methods here.
https://www.lua.org/pil/5.html
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.