Tuesday, October 14, 2008

Javascript Trim Function Problem

There is no function to trim string in javascript. We can use following user define function to trim string using javascript. Mainly we need three type of trim function which we use in program.

Right Trim Javascript User Define function.

function rightTrim(str)
{
return str.replace(/\str+$/,"");
}

Left Trim Javascript User Define function.

function leftTrim(str)
{
return str.replace(/^\str+/,"");
}

Trim javascript function for both left and right side.

function trim(str)
{
return str.replace(/^\str+|\str+$/g,"");
}

No comments:

Post a Comment