By 05/02/2014 12 Comments

How to Trimming a string in Javascript

String Trim() method

  • This can be used to remove spaces from both sides of a string.
  • It is a builtin method / function of a string object

Following is a simple example of trim() function

<script>
if (!String.prototype.trim) {
String.prototype.trim=function() {
return this.replace(/^\s+|\s+$/g, '');
};
}

//usage
var str = " some string "; // assign string which has a space from it's both sides, which will be used by trim function
str.trim(); // call trim() function by string object str followed by .dot
//print str = "some string" // this is string which can be seen as an output

</script>






Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .