StringExtension.cs 824 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace GreenTree.Strohrmann.ERP.Core.Extension
  5. {
  6. public static class StringExtension
  7. {
  8. /// <summary>
  9. /// Évaluates a string between a starting and an endling string part
  10. /// </summary>
  11. /// <param name="str">Base string.</param>
  12. /// <param name="start">Beginning string part.</param>
  13. /// <param name="end">Ending string part.</param>
  14. public static string Between(this string str, string start, string end)
  15. {
  16. var startIndex = str.IndexOf(start) + start.Length;
  17. var endIndex = str.IndexOf(end, startIndex);
  18. return end == String.Empty
  19. ? str.Substring(startIndex)
  20. : str[startIndex..endIndex];
  21. }
  22. }
  23. }