StringExtensions.cs 841 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Emby.Naming
  5. {
  6. internal static class StringExtensions
  7. {
  8. public static string Replace(this string str, string oldValue, string newValue, StringComparison comparison)
  9. {
  10. var sb = new StringBuilder();
  11. var previousIndex = 0;
  12. var index = str.IndexOf(oldValue, comparison);
  13. while (index != -1)
  14. {
  15. sb.Append(str.Substring(previousIndex, index - previousIndex));
  16. sb.Append(newValue);
  17. index += oldValue.Length;
  18. previousIndex = index;
  19. index = str.IndexOf(oldValue, index, comparison);
  20. }
  21. sb.Append(str.Substring(previousIndex));
  22. return sb.ToString();
  23. }
  24. }
  25. }