JSFiddle - React, Tailwind, and code Playground

by Sajjad Ashrah

JavaScript

/*
*****************************
Remove White spaces
by   : http://visualstudiolearn.blogspot.com/
tpic : Attached as methods of the String object
use to uncommit code to check output.
*****************************/

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

var myString = " hello my name is ";
alert("*"+myString.trim()+"*");
/*alert("*"+myString.ltrim()+"*");
alert("*"+myString.rtrim()+"*");*/
/*
*****************************
Remove specified Character
by http://visualstudiolearn.blogspot.com/
*****************************/
String.prototype.rtrim = function(s) { 
    return this.replace(new RegExp(s + "*$"),''); 
};
String.prototype.ltrim = function(s) { 
    return this.replace(new RegExp("^"+s  ),''); 
};
String.prototype.trim = function(s) { 
    var regex = new RegExp(s, 'g');
    return this.replace(regex,''); 
};

var s1 = "~this is a test~";
var s = s1.trim('~');
alert(s); 
/*
*****************************
More Detail and Tutorial  Visit http://visualstudiolearn.blogspot.com/2014/01/java-script-trim-ltrim-and-rtrim.html
*****************************/