These function lTrim, rTrim and Trim let you use the trim functionality in Flash…….
ltrim trims from left side, rTrim from right side and trim from both end..
// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from left side.
function lTrim(str) {
if ((str.length>1) || (str.length == 1 && str.charCodeAt(0)>32 && str.charCodeAt(0)<255)) {
i = 0;
while (i<str.length && (str.charCodeAt(i)<=32 || str.charCodeAt(i)>=255)) {
i++;
}
str = str.substring(i);
} else {
str = “”;
}
return str;
}
// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from right side.
function rTrim(str) {
if ((str.length>1) || (str.length == 1 && str.charCodeAt(0)>32 && str.charCodeAt(0)<255)) {
i = str.length-1;
while (i>=0 && (str.charCodeAt(i)<=32 || str.charCodeAt(i)>=255)) {
i–;
}
str = str.substring(0, i+1);
} else {
str = “”;
}
return str;
}
// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from both sides.
function Trim(str) {
return lTrim(rTrim(str));
}