exd.mi 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //----------------------------------------------------------------------------------------------------------------
  2. // exd.mi
  3. //
  4. // extra definitions for internal objects
  5. //----------------------------------------------------------------------------------------------------------------
  6. #ifndef included
  7. #error This script can only be compiled as a #include
  8. #endif
  9. #ifndef __EXD_MI
  10. #define __EXD_MI
  11. //*****************************************************************************
  12. // String CLASS
  13. //*****************************************************************************
  14. Function String replaceString(string baseString, string toreplace, string replacedby);
  15. /**
  16. replaceString()
  17. Returns the class name for the object.
  18. @param baseString The String which you want to modify.
  19. @param toreplace The String you want to be replaced.
  20. @param replacedby The String instead of 'toreplace'.
  21. @ret The replaced string.
  22. */
  23. String replaceString(string baseString, string toreplace, string replacedby) {
  24. if (toreplace == "") return baseString;
  25. string sf1 = strupper(baseString);
  26. string sf2 = strupper(toreplace);
  27. int i = strsearch(sf1, sf2);
  28. if (i == -1) return baseString;
  29. string left = "", right = "";
  30. if (i != 0) left = strleft(baseString, i);
  31. if (strlen(basestring) - i - strlen(toreplace) != 0) {
  32. right = strright(basestring, strlen(basestring) - i - strlen(toreplace));
  33. }
  34. return left + replacedby + right;
  35. }
  36. Function String cutString(string baseString, string toreplace);
  37. /**
  38. cutString()
  39. Returns the class name for the object.
  40. @param baseString The String which you want to modify.
  41. @param toreplace The String you want to be replaced.
  42. @ret The replaced string.
  43. */
  44. String cutString(string baseString, string toreplace) {
  45. if (toreplace == "") return baseString;
  46. int i = strsearch(baseString, toreplace);
  47. if (i == -1) return baseString;
  48. string left = "", right = "";
  49. if (i != 0) left = strleft(baseString, i);
  50. if (strlen(basestring) - i - strlen(toreplace) != 0) {
  51. right = strright(basestring, strlen(basestring) - i - strlen(toreplace));
  52. }
  53. return left + right;
  54. }
  55. Function String fillStringBefore(string baseString, string after, string before);
  56. /**
  57. fillStringBefore()
  58. Returns the class name for the object.
  59. @param baseString The String which you want to modify.
  60. @param toreplace The String you want to be replaced.
  61. @ret The replaced string.
  62. */
  63. String fillStringBefore(string baseString, string filled, string anchor) {
  64. int i = strsearch(baseString, anchor);
  65. if (i == -1) return baseString;
  66. string left = "", right = "";
  67. if (i != 0) left = strleft(baseString, i);
  68. if (strlen(basestring) - i - strlen(toreplace) != 0) {
  69. right = strright(basestring, strlen(basestring) - i);
  70. }
  71. /* bef.setText(integerToString(i) + " - " + left);
  72. aft.setText(integerToString(strlen(basestring) - i) + " - " + right);
  73. */ return left + filled + right;
  74. }
  75. Function Int countSubString(string str, string substr);
  76. int countSubString(string str, string substr) {
  77. int n = 0;
  78. for ( int i = 0; i < 666; i++ ) {
  79. int r = strSearch(str, substr);
  80. #ifdef DEBUG
  81. debug(integerToString(r));
  82. #endif
  83. if (r == -1) i = 666;
  84. else {
  85. str = strright(str, strlen(str) - (r + 1));
  86. n++;
  87. if (strlen(str) - r == 1) return n;
  88. }
  89. }
  90. return n;
  91. }
  92. #endif