Skip to content

Instantly share code, notes, and snippets.

@stdarg
Created February 28, 2014 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stdarg/9278904 to your computer and use it in GitHub Desktop.
Save stdarg/9278904 to your computer and use it in GitHub Desktop.
Trim a string
/**
* A simple function that creates a new string from inputStr and removes bot h * leading and trailing sep strings.
* @param {String} inputStr The string to be trimmed.
* @param {String} sep The separator string to be trimmed.
* @private
*/
function ctrim(inputStr, sep) {
var str = String(inputStr);
var regExpStr = '^'+sep+'+|'+sep+'+$';
console.log('sep ',sep);
console.log('str - 1',str,regExpStr);
var rExp = new RegExp(regExpStr, 'gm');
str.replace(rExp, '');
console.log('str - 2',str);
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment