javascript string methods


/ Published in: JavaScript
Save to your folder(s)

sample:
var text = " string content ";

text = text.trim();


Copy this code and paste it in your HTML
  1. String.prototype.trim = function() {
  2. return this.replace(/^\s+|\s+$/g,"");
  3. }
  4. String.prototype.ltrim = function() {
  5. return this.replace(/^\s+/,"");
  6. }
  7. String.prototype.rtrim = function() {
  8. return this.replace(/\s+$/,"");
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.