Rich text seems to be the easiest solution:
“this is <b>BOLD</b>”
becomes
“this is BOLD”
inside a textbox with RichText set to true
so if you want “this is ~~BOLD~~”
to become “this is BOLD”
you can use a script replace the 1st ~~ with <b> and 2nd ~~ with </b>
we can simply use string.gsub to replace instances of “~~”. we can also use a variable to keep track of whether we are inside or outside the pattern so we know if we need to replace it with <b> or </b>
we can place it in a loop as follows:
local text = "testing testing testing ~~BOLD~~ testing testing ~~BOLD AGAIN~~" -- our test text
local inside = false
local currenttext,amt = string.gsub(text,"~~","<b>",1) -- see if theres more stuff
while amt>0 do
inside = not inside
if inside == true then
currenttext,amt = string.gsub(currenttext,"~~","</b>",1)
else
currenttext,amt = string.gsub(currenttext,"~~","<b>",1)
end
end
print(currenttext)
this works with multiple patterns:
local currenttext = "testing **underline** testing ~~BOLD~~ testing testing ~~BOLD AGAIN~~ test ~~**BOLD AND UNDERLINE**~~" -- our test text
local inside = false
currenttext,amt = string.gsub(currenttext,"~~","<b>",1) -- see if theres more stuff
while amt>0 do
inside = not inside
if inside == true then
currenttext,amt = string.gsub(currenttext,"~~","</b>",1)
else
currenttext,amt = string.gsub(currenttext,"~~","<b>",1)
end
end
local inside = false
currenttext,amt = string.gsub(currenttext,"%*%*","<u>",1)
while amt>0 do
inside = not inside
if inside == true then
currenttext,amt = string.gsub(currenttext,"%*%*","</u>",1)
else
currenttext,amt = string.gsub(currenttext,"%*%*","<u>",1)
end
end
print(currenttext)
you may have noticed that i had to put “%” before “*”. this is because it is a “magic” character and has special meanings. we can use “%” to escape it and use it like a normal character. be wary of this.
anyways this is what the string looks like on a textbox with richtext enabled:
oh yeah, for your example, the same logic should apply to differentiating between “***”, “**”, and “*”. you just have to replace the longest pattern first so that the long pattern doesn’t get mistaken for many short patterns.
for example,
you’d replace “***” with <i><b> and </i></b>
then
“**” with <b> and </b>
and finally
“*” with <i> and </i>