Tech Tip: Removing characters from a string in Javascript
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: August 7, 2006
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;
}