Javascript String strip()

Description

Javascript String strip()


String.prototype.strip = function() {
  return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

Javascript String strip()

String.prototype.strip = function() {
  return this.replace(/^\s+|\s+$/g,"");
};

Javascript String strip()

var DECODE_HTML_CHARACTERS = {
    'nbsp': ' ',
    'amp': '&',
    'quot': '"',
    'lt': '<',
    'gt': '>'
};

String.prototype.strip = function() {
    var self = this.replace(/<\/?[^>]+(>|$)/g, '');
    return self.replace(/&(nbsp|amp|quot|lt|gt);/g, function(match, k) {
        return DECODE_HTML_CHARACTERS[k] || k;
    });//  w  w  w .  jav a 2  s.c o m
};

Javascript String strip()

//assignment: check string to see if it is a palindrome

String.prototype.strip = function() {
  return this.replace(/\W?\s+/g,"");
};

function palindrome(str) {
  var stripped = str.toLowerCase().strip();
  var reversed = stripped.split("").reverse().join("");
  if (stripped === reversed) {
      return true;    
  } else {// ww  w .ja v a  2 s.  c  o m
      return false;
  }

}

palindrome("eye");

palindrome("lasagna is an asian gas al");

Javascript String strip()

String.prototype.strip = function()
{
return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

Javascript String strip()

String.prototype.strip = function() {
 return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/:$/, "").replace(/\.$/, "");
}

Javascript String strip()

String.prototype.strip = function(){
    return this.replace(/(^\s+|\s$)/gi, '');
};

Javascript String strip()

String.prototype.strip = function () {
  var s = this.valueOf();
  s = s.replace(/([\s]+$)/, '');
  s = s.replace(/(^[\s]+)/, '');
  return s;/*from   w  ww  .  j ava2s .c o m*/
};



PreviousNext

Related