Created
May 14, 2014 22:08
-
-
Save baniol/e6ebe222b0209d27d633 to your computer and use it in GitHub Desktop.
strip whitespaces, javascript, string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove leading and trailing whitespace | |
// Requires jQuery | |
var str = " a b c d e f g "; | |
var newStr = $.trim(str); | |
// "a b c d e f g" | |
// Remove leading and trailing whitespace | |
// JavaScript RegEx | |
var str = " a b c d e f g "; | |
var newStr = str.replace(/(^\s+|\s+$)/g,''); | |
// "a b c d e f g" | |
// Remove all whitespace | |
// JavaScript RegEx | |
var str = " a b c d e f g "; | |
var newStr = str.replace(/\s+/g, ''); | |
// "abcdefg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment