PathExtensions.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace MediaBrowser.Server.Implementations.Library
  3. {
  4. public static class PathExtensions
  5. {
  6. /// <summary>
  7. /// Gets the attribute value.
  8. /// </summary>
  9. /// <param name="str">The STR.</param>
  10. /// <param name="attrib">The attrib.</param>
  11. /// <returns>System.String.</returns>
  12. /// <exception cref="System.ArgumentNullException">attrib</exception>
  13. public static string GetAttributeValue(this string str, string attrib)
  14. {
  15. if (string.IsNullOrEmpty(str))
  16. {
  17. throw new ArgumentNullException("str");
  18. }
  19. if (string.IsNullOrEmpty(attrib))
  20. {
  21. throw new ArgumentNullException("attrib");
  22. }
  23. string srch = "[" + attrib + "=";
  24. int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
  25. if (start > -1)
  26. {
  27. start += srch.Length;
  28. int end = str.IndexOf(']', start);
  29. return str.Substring(start, end - start);
  30. }
  31. return null;
  32. }
  33. }
  34. }