Skip to content

Instantly share code, notes, and snippets.

@Karlina-Bytes
Created October 16, 2014 23:16
Show Gist options
  • Save Karlina-Bytes/8ee90fdb1e45f787cbc0 to your computer and use it in GitHub Desktop.
Save Karlina-Bytes/8ee90fdb1e45f787cbc0 to your computer and use it in GitHub Desktop.
A JavaScript function for removing spaces in a string.
/*********************************************************
* Removes space characters from the input string.
* @param {String} inputString
* @return {String} "cleaned up" inputString.
*********************************************************/
function removeSpaces( inputString ) {
// If the inputString is empty, return an error.
if (!inputString) return "Error";
/**
* For each character in inputString,
* if the character is NOT a space character,
* append it to the string to return.
*/
var modifiedString = "";
for (var i in inputString)
if (inputString[i] != " ")
modifiedString += inputString[i];
// Return de-spaced string.
return modifiedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment