Hey devforum! I’ve been stuck on this for quite a minute now. I was writing a library for manipulating markdown and needed a quick and simple way to parse the markdown.
I ended up with just deciding to write my own format function.
Here’s the code:
local function join(t: {string})
local s = ""
for i,v in t do
s = s..v
end
return s
end
-- // The point of this function is to allow easy parsing of markdown.
-- // The first arg is a string and you can think of it to be like a format string.
-- // The second arg is a string to format it with.
-- // The idea behind this is we compare formatWith to str and replace what's different in str with what's in formatWith.
local function format(str: string, formatWith: string)
local readableStr = str:split("")
local readableFormatWith = formatWith:split("")
for i,v in readableFormatWith do
if readableStr[i] == v then
readableFormatWith[i] = ""
end
end
formatWith = join(readableFormatWith)
return string.format(str, formatWith)
end
print(format("*%q*", "*hi*"))
Output: *"hi"*
Expected Output: *hi*
It’s not an issue with the join function as I have tested it prior.
Any help is much appreciated and thank you in advance!
