Modifying a character in a string in Lua

Is there any way to replace a character at position N in a string in Lua.

This is what I've come up with so far:

function replace_char(pos, str, r)
    return str:sub(pos, pos - 1) .. r .. str:sub(pos + 1, str:len())
end

str = replace_char(2, "aaaaaa", "X")
print(str)

I can't use gsub either as that would replace every capture, not just the capture at position N.

6
задан hjpotter92 18 September 2013 в 14:18
поделиться