ExtensionString.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. public static class ExtensionString
  5. {
  6. public static T ToEnum<T>(this string str)
  7. {
  8. return (T)Enum.Parse(typeof(T), str);
  9. }
  10. public static string Remove(this string str, int startIndex, int endIndex, bool empty)
  11. {
  12. if (startIndex > endIndex)
  13. {
  14. throw new Exception();
  15. }
  16. return str.Remove(startIndex, endIndex - startIndex + 1);
  17. }
  18. public static string Replace(this string str, int startIndex, int endIndex, string newStr)
  19. {
  20. str = str.Remove(startIndex, endIndex - startIndex + 1);
  21. str = str.Insert(startIndex, newStr);
  22. return str;
  23. }
  24. public static string Between(this string str, int startIndex, int endIndex)
  25. {
  26. if (startIndex > endIndex)
  27. {
  28. return "";
  29. }
  30. else if (startIndex == endIndex)
  31. {
  32. return str[startIndex].ToString();
  33. }
  34. else
  35. {
  36. return str.Substring(startIndex, endIndex - startIndex + 1);
  37. }
  38. }
  39. }