Strip Character and Whitespace in JavaScript Function
This JavaScript function will strip every instance of any specified character (including whitespace) from a string in JavaScript.
Function Name: stripCharacter(words,character)
Example of output:
string="This , is , a , broken , sentence.";
string = stripCharacter(string,',');
The string converts to "This is a broken sentence."
To use this script, copy this link and place it in the head of your HTML before any other JavaScript that may use it.
Please include credit when using this script and read this site's Terms & Conditions before using.
One known issue is that to strip a whitespace, you may have to type stripCharacter(string,' ') rather than stripCharacter(string," ") -- for some reason the double quotes has errors.
2011-11-03 This was one of the first JavaScript functions I shared. It is actually a very primitive function that is only useful if you are brand new to JavaScript and don't have time/need to actually learn JavaScript... as the function can be handled very easily with standard JavaScript string functions.
- Related Topics
Otto Teixeira
Oct 5, 2009
Reply
Shawn Olson
Oct 5, 2009
Reply
louis tsoi
Apr 4, 2007
Reply