git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / string.js
diff --git a/doc/webdeveloper/common/string.js b/doc/webdeveloper/common/string.js
new file mode 100644 (file)
index 0000000..fd9709a
--- /dev/null
@@ -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"), "");
+}