I want to turn this:
s = 'I need you to <h>Listen</h> to me'
To this:
s = 'I need you to <font color="#FF7800">Listen</font> to me'
Currently I have this overcomplicated code that I believe could be a lot better
function replace_char3(pos, endpos, str, r)
return table.concat{str:sub(1,pos-1), r, str:sub(endpos+5)}
end
local promptText = "I need you to <h>Listen</h> to me"
local capturePhrase = string.match(promptText, '<h>(.*)</h>')
promptText = promptText:gsub("<h>", "")
local startIndexOfPhrase, endIndex = string.find(promptText, capturePhrase)
capturePhrase = '<font color="#FF7800">' .. capturePhrase .. '</font>'
promptText = replace_char3(startIndexOfPhrase, endIndex, promptText, capturePhrase)
print(promptText) -- 'I need you to <font color="#FF7800">Listen</font> to me'
The “replace_char3” function reference: