Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. namespace Utils
  2. {
  3. public static class Util
  4. {
  5. public static string InBetween(string haystack, string afterThis, string beforeThis)
  6. {
  7. return InBetween(haystack, afterThis, beforeThis, 1, 0);
  8. }
  9.  
  10. public static string InBetween(string haystack, string afterThis, string beforeThis,
  11. int afterIndex, int beforeIndex, bool includeAfterAndBefore = false)
  12. {
  13. if (haystack == null) return null;
  14.  
  15. if (haystack.Contains(afterThis))
  16. {
  17. var split = Split(haystack, afterThis);
  18. if (split.Length > afterIndex)
  19. {
  20. string rv = split[afterIndex];
  21. if (rv.Contains(beforeThis))
  22. {
  23. split = Split(rv, beforeThis);
  24. if (split.Length > beforeIndex)
  25. {
  26. rv = split[beforeIndex];
  27.  
  28. if (includeAfterAndBefore)
  29. {
  30. rv = $"{afterThis}{rv}{beforeThis}";
  31. }
  32.  
  33. return rv;
  34. }
  35. }
  36. }
  37. }
  38. return null;
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment