Is there a way to get the length of text, maybe an algorithm using the textsize?
Im trying to shadow what the user writes with a frame, and I would need the size of the text itself to do that.
Thanks.
Is there a way to get the length of text, maybe an algorithm using the textsize?
Im trying to shadow what the user writes with a frame, and I would need the size of the text itself to do that.
Thanks.
To get a string's length, you can either use string.len() or the length operator (#).
local importantString = "g";
print(#importantString);
print(string.len(importantString));
print(importantString:len());
All three of these would print 1.
However, looking at your problem, I think you may need something like TextBounds instead:
local label = someTextLabel;
local bounds = label.TextBounds;
--// bounds would be a Vector2 value representing the text size, if that's what you meant. You could then get the x portion of it...
print(bounds.X);
--// ... which would be its "length".
Hope this helped!
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
string:len() or #string
if #script.Parent.Text > 20 then script.Parent.Text = script.Parent.Text:sub(1,20) end