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

Getting the length of text?

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.

2 comments

0

string:len() or #string

0

if #script.Parent.Text > 20 then script.Parent.Text = script.Parent.Text:sub(1,20) end

1 answer

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.