News, stories and adventures from the team that created the first HTML5 diagram editor
Monday, February 21, 2011
JavaScript - Trim a string
I need to trim strings in JavaScript every day and everytime I forgot the code snippet that do that so here is
/**Trims a string *@param {String} str - the string to trim *@return {String} the trimmed string **/ function trim(str){ var res = str.replace(/^\s+/, ''); res = res.replace(/\s+$/, '');
No comments:
Post a Comment