Monday, December 31, 2007

Trim Function in Javascript

Copy and Paste the following in code between <script> tags.

String.prototype.trim = function()
{
return( this.replace(new RegExp("^([\\s]+)([\\s]+)$", "gm"), ""));
};


We can use this function like,

var s = " Success Within You ";
alert(s.trim());


You will get "Success Within You"

2 comments:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Aluguel de Computadores, I hope you enjoy. The address is http://aluguel-de-computadores.blogspot.com. A hug.

hsp said...
This comment has been removed by the author.