X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=doc%2Fwebdeveloper%2Fcommon%2Fstring.js;fp=doc%2Fwebdeveloper%2Fcommon%2Fstring.js;h=fd9709af5959384f488c3d2ea0144d98f4a86692;hb=c3b0deb3d8c9f439739c79806e915c29bc1d4b84;hp=0000000000000000000000000000000000000000;hpb=cff6539539a79e014f6ac8df46716cafce2c8472;p=pompage.git diff --git a/doc/webdeveloper/common/string.js b/doc/webdeveloper/common/string.js new file mode 100644 index 0000000..fd9709a --- /dev/null +++ b/doc/webdeveloper/common/string.js @@ -0,0 +1,31 @@ +// Removes a substring from a string +function webdeveloper_removeSubstring(string, substring) +{ + // If the strings are not empty + if(string && substring) + { + var substringStart = string.indexOf(substring); + + // If the substring is found in the string + if(substring && substringStart != -1) + { + return string.substring(0, substringStart) + string.substring(substringStart + substring.length, string.length); + } + + return string; + } + + return ""; +} + +// Tests if a string ends with the given string +String.prototype.endsWith = function(endsWithString) +{ + return (this.substr(this.length - endsWithString.length) == endsWithString); +} + +// Trims leading and trailing spaces from a string +String.prototype.trim = function() +{ + return this.replace(new RegExp("^\\s+|\\s+$", "gi"), ""); +}