title: Modifying a character in a string in Lua
body: <p>Is there any way to replace a character at position N in a string in Lua.</p>
  
  <p>This is what I've come up with so far:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I can't use gsub either as that would replace every capture, not just the capture at position N.</p>