git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / string.js
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 }