title: C# Regex: How Can I Replace Tokens With Strings Generated at Run-time?
body: <p>Given the following input and regex strings:</p>
  
  <pre><code>const string inputString = "${Principal}*${Rate}*${Years}";
  const string tokenMatchRegexString = @"\${([^}]+)}";
  </code></pre>
  
  <p>How can I replace each token (i.e. ${Principal}, ${Rate}, and ${Years}) with the return value of my 'ReplaceToken' function?</p>
  
  <pre><code>private static string ReplaceToken(string tokenString)
  {
      switch (tokenString)
      {
          case "Principal":
              return GetPrincipal();
          case "Rate":
              return GetRate();
          case "Years":
              return GetYears();
          default:
              throw new NotImplementedException(String.Format("A replacment for the token '{0}' has not been implemented.", tokenString));
      }
  }
  
  private static string GetPrincipal()
  {
      throw new NotImplementedException();
  }
  
  private static string GetRate()
  {
      throw new NotImplementedException();
  }
  
  private static string GetYears()
  {
      throw new NotImplementedException();
  }
  </code></pre>