Trimming whitespace in Javascript
Unlike most programming languages, Javascript does not have a built-in method to allow trimming white space off of strings. If you want to perform trimming of white space in Javascript, here are some functions you can use to perform this functionality.
function trimString(inString) {
// Trims space from the left and right sides of the string
return inString.replace(/^\s+|\s+$/g, "");
}
function trimStringLeft(inString) {
// Trims space from the left side of a string
return inString.replace(/^\s+/g, "");
}
function trimStringRight(inString) {
// Trims space from the right side of a string
return inString.replace(/\s+$/g, "");
}
| Rating: | 100% positive, 3 total Votes |
| Categories: | javascript programming |
| Added: | on Sep 13, 2007 at 1:54 pm |
| Added By: | an anonymous user |
| Searches: | javascript programming trimming space white |

