I want to separate text onto multiple lines based on if it’s got a space. I know /n separates a text in a TextLable to multiple lines For example
local Text1 = "Hello"
local Text2 = "Hello World"
local Text3 = "Hello World Again"
-- Text1 on 1 line
-- Text2 on 2 lines
-- Text3 on 3 lines
1 Like
rapmilo
(rapmilo)
December 24, 2020, 4:30pm
#2
Look into using RichText. This will allow you a lot more flexibility in formatting text: Rich Text Markup | Documentation - Roblox Creator Hub
I’m a bit confused, do you want to check if it has a space and then add /n?
rapmilo
(rapmilo)
December 24, 2020, 4:41pm
#4
It’s \n (backslash n), and, if I’m understanding him correctly, he wants to space each word into a separate line which would require RichText. Using a \n doesn’t separate text into separate lines on GUI text objects.
EDIT: You can scriptably space lines using \n (see below for more)
1 Like
korky5000
(korky5000)
December 24, 2020, 4:45pm
#5
You could just swap the spaces with “\n” using gsub.
myString = myString:gsub(" ", "\n")
1 Like
Actually it does make text turn into multiple lines without richtext.
1 Like
rapmilo
(rapmilo)
December 24, 2020, 4:47pm
#7
Nevermind, I redact that statement. You can space text using \n, but through script.
game.StarterGui.ScreenGui.TextLabel.Text = "Hello".."\n".."World"
This spaced the text for me when run through the command line and fixed the above issue!
3 Likes
Auxintic
(Aux)
December 24, 2020, 4:47pm
#8
An easy way to do this would look something like this:
local text = "Hello World Again"
local separatedText = table.concat(string.split(text, " "), "\n")
print(separatedText)
Then you could set the .Text
property of a TextElement (TextLabel, TextButton) equal to seperatedText
like this:
textLabel.Text = separatedText
Another solution would be to use string patterns like @korky5000 suggested.
Its_guus
(Herbertoes)
April 13, 2023, 4:28pm
#9
I guess you could also use a “UIListLayout” insid of a frame, if you put your different text objects in there (If Text1-2 and 3 are seperate texts) it would automatically line them up in a list/paragraph way.
(This can also be combined with a ScrollingFrame)
If this is not what you want to achieve then forget whatever I have said.