StringExtensions.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #if UNITY_EDITOR
  2. namespace O3DWB
  3. {
  4. public static class StringExtensions
  5. {
  6. #region Extension Methods
  7. public static string RemoveTrailingSlashes(this string str)
  8. {
  9. string finalString = str;
  10. while (finalString.LastChar() == '\\' || finalString.LastChar() == '/')
  11. {
  12. finalString = finalString.Substring(0, finalString.LastCharIndex());
  13. }
  14. return finalString;
  15. }
  16. public static char LastChar(this string str)
  17. {
  18. return str[str.LastCharIndex()];
  19. }
  20. public static int LastCharIndex(this string str)
  21. {
  22. return str.Length - 1;
  23. }
  24. public static bool ContainsOnlyWhiteSpace(this string str)
  25. {
  26. for(int charIndex = 0; charIndex < str.Length; ++charIndex)
  27. {
  28. if (!char.IsWhiteSpace(str[charIndex])) return false;
  29. }
  30. return true;
  31. }
  32. public static bool IsSingleDigit(this string str)
  33. {
  34. return str.Length == 1 && char.IsDigit(str[0]);
  35. }
  36. public static bool IsSingleLetter(this string str)
  37. {
  38. return str.Length == 1 && char.IsLetter(str[0]);
  39. }
  40. public static bool IsSingleChar(this string str, char character)
  41. {
  42. return str.Length == 1 && str[0] == character;
  43. }
  44. #endregion
  45. }
  46. }
  47. #endif