title: Safely and efficiently parse and replace tokens in a string
body: <p>I'm trying to write a VBA function that will do some parsing / replacement according to tokens / placeholders.</p>
  
  <p>Example:
  Input: <code>"Username %u, date is %d."</code><br>
  The function would replace %d with the current date and %u with the current username.</p>
  
  <p>Sounds simple to implement, but here's a twist:
  Regexps and Replace() are not safe. In the example above, if %u after replacement would contain another token (let's say <code>"Andy%d"</code>), there will be a recursive replacement and the output will mangled: <code>"Username Andy20170820, date is 20170820"</code>.</p>
  
  <p>I could write this efficiently in C++ or some other <em>"proper"</em> language but I'm relegated to the VBA. I don't want to work on Chars inside a string as that doesn't look very efficient (and I might be using this formula to parse 10000 lines in an Excel sheet).</p>
  
  <p>Searched and googled and even DuckDuckWent but to no avail.</p>