MacroReplacement.cs 727 B

123456789101112131415161718192021222324252627
  1. using System.Collections.Generic;
  2. using System.Text.RegularExpressions;
  3. namespace YBEE.EQM.Core
  4. {
  5. /// <summary>
  6. /// 宏替换
  7. /// </summary>
  8. public class MacroReplacement
  9. {
  10. /// <summary>
  11. /// 宏替换
  12. /// </summary>
  13. /// <param name="input">要替换的字符串</param>
  14. /// <param name="macros">宏字典</param>
  15. /// <returns></returns>
  16. public static string Replace(string input, Dictionary<string, string> macros)
  17. {
  18. foreach (var macro in macros)
  19. {
  20. var regex = new Regex(macro.Key);
  21. input = regex.Replace(input, macro.Value);
  22. }
  23. return input;
  24. }
  25. }
  26. }