//for left trim
function ltrim(str) {
for(var k = 0; k < str.length && checkSpace(str.charAt(k)); k++);
return str.substring(k, str.length);
}
//for right trim
function rtrim(str) {
for(var j=str.length-1; j>=0 && checkSpace(str.charAt(j)) ; j--) ;
return str.substring(0,j+1);
}
//for trim
function trim(str) {
return ltrim(rtrim(str));
}
function checkSpace(ch) {
var spaceChars = " \t\n\r\f";
return (spaceChars.indexOf(ch) != -1);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment