Trim Function in javascript


function trim(str) {
if (str != null) {
var i;
for (i=0; i=0; i–) {
if (str.charAt(i)!=” “) {
str=str.substring(0,i+1);
break;
}
}

if (str.charAt(0)==” “) {
return ” “;
} else {
return str;
}
}
else
{
return ” “;
}
}

Advertisements

One comment on “Trim Function in javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s