KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Removing characters from a string in Javascript
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: August 7, 2006
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

This javascript function is a good addition to a developer's Javascript "toolbox". The function will remove all instances of a character from a passed string.

Example call:

newString = strip(oldString, "-");

where newString is "01022003" and oldString is "01-02-2003".

// remove all instances of char from a string
function strip(string, symbol) {
   var newstring = "";

      for (var i = 0; i < string.length; i++) {
         if (string.charAt(i) != symbol)
            newstring += string.charAt(i);
   }
   return newstring;
}