home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60 / 60.xpi / chrome / webdeveloper.jar / content / webdeveloper / common / string.js < prev    next >
Encoding:
JavaScript  |  2009-06-30  |  881 b   |  32 lines

  1. // Removes a substring from a string
  2. function webdeveloper_removeSubstring(string, substring)
  3. {
  4.     // If the strings are not empty
  5.     if(string && substring)
  6.     {
  7.         var substringStart = string.indexOf(substring);
  8.  
  9.         // If the substring is found in the string
  10.         if(substring && substringStart != -1)
  11.         {
  12.             return string.substring(0, substringStart) + string.substring(substringStart + substring.length, string.length);
  13.         }
  14.  
  15.         return string;
  16.     }
  17.  
  18.     return "";
  19. }
  20.  
  21. // Tests if a string ends with the given string
  22. String.prototype.endsWith = function(endsWithString)
  23. {
  24.     return (this.substr(this.length - endsWithString.length) == endsWithString);
  25. }
  26.  
  27. // Trims leading and trailing spaces from a string
  28. String.prototype.trim = function()
  29. {
  30.     return this.replace(new RegExp("^\\s+|\\s+$", "gi"), "");
  31. }
  32.