for i = 1,text:len() do label.Text = text:sub(1,i) wait(0.1) end
I usually don't work with for loops, so I searched around wiki and there was nothing that really explained :sub() very well,
I'm finishing a script for a friend, and it's a simple 10 line script, except there's nothing saying anything about :len() on wiki or in the script, so I'm wondering if any of you know.
string.len()
is a string function that returns the length of the given string. This will return the length of the string including any and all characters. You can either use this as a function;
local str = "Hello, i'm bob" print(string.len(str)) --> 14
Or, you can use this as a method of the specified string;
local str = "Hello, i'm bob" print(str:len()) --> 14
A shorter alternative to this is using the #
operator, which will also return the length of any given string, as well as tables!
local str = "Hello, i'm bob" print(#str) --> 14
string.sub()
is a function that returns substrings of the given string. Substrings are portion of a string. You can determine what portion of said string will be returned with the arguments of this function.
There are a few ways you can use string.sub
.
Where string would be the string you're getting the substring from, start would be the start of the substring, what place in the string argument.. 1 is the first letter, 3 is the second letter.. you get the point.. and stop would be the end of the substring.
local str = "Hello, world" local substring = string.sub(str,3,6) print(substring) --> llo,
Same rules as the previous apply, just now it will get any and all characters after the given start place
local str = "Hello, world" local substring = string.sub(str,8) print(substring) --> world
Note: As for the start, and stop arguments.. negative numbers count backwards in the string(: -1 would be the last letter, -2 would be the second to last letter, etc..
:len() is the total amount of Characters in a string example "Dog" has a :() len of 3, now sub is like a cutoff example
Example = "apple" print(Example:sub(2,5))
This would print "pple" because it only goes to the beginning set variable and the end