I’m trying to add brackets to a RichText that originally has no brackets, so instead of this: <a>b</c>
, It should be <a>[b]</c>
. Problem is, I don’t really know how to mess around with string formatting, so could anyone help me out?
You can use string.format() along with its specifiers to input variables into strings as seen below
local richText = 'b' -- Bold
local message = 'hi'
print(string.format("<%s>[%s]</%s>", richText, message, richText)) --> <b>[hi]</b>
1 Like
Sort of helps out, but its a whole string and not separated with variables, looks something like this: <font color="rgb(0, 255, 0)">asd</font>
, but thanks! I’ll try doing something with it.
Ok, did lots of digging, couldn’t find a right solution with that… Here’s max I got:
local str = '<font color="rgb(128, 0, 255)">developer 🌙</font>'
local r1 = string.match(str, '^<.+">')
local r2 = string.match(str, '</.+>$')
local t = string.gsub(str, "["..r1.."|"..r2.."]", "")
print(string.format("%s[%s]%s", r1, t, r2))
The output of the main text comes out as devepe🌙
, it should be developer 🌙
. Think you can fix it?
Never mind! Did some more digging, found a post that helped me out! Here’s the final code:
local str = '<font color="rgb(128, 0, 255)">developer 🌙</font>'
print(string.format("%s[%s]%s", string.match(str, '^<.+">'), string.gsub(str, "<[^<>]->", ""), string.match(str, '</.+>$')))
-- > <font color="rgb(128, 0, 255)">[developer 🌙]</font>
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.