splendorx
asked on
Flash Trim Function
I am trying to trim a string with extra white space and line breaks. I a have tried using the following AS from:
https://www.experts-exchange.com/questions/20294500/Trim-the-spaces-off-a-string.html?query="flash+trim"&clearTAFilter=true
Example:
function LTrim(str) {
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.char At(0)) != -1) {
var j = 0, i = s.length;
while (j<i && whitespace.indexOf(s.charA t(j)) != -1) {
j++;
}
s = s.substring(j, i);
}
return s;
}
function RTrim(str) {
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.char At(s.lengt h-1)) != -1) {
var i = s.length-1;
while (i>=0 && whitespace.indexOf(s.charA t(i)) != -1) {
i--;
}
s = s.substring(0, i+1);
}
return s;
}
function Trim(str) {
return LTrim(RTrim(str));
}
myString = "hello world ";
trace(myString);
Trim(myString);
trace(str);
The str trace comes back as undefined. Is there something wrong with the syntax? Any other suggestions for a trim function?
TIA,
Terry
https://www.experts-exchange.com/questions/20294500/Trim-the-spaces-off-a-string.html?query="flash+trim"&clearTAFilter=true
Example:
function LTrim(str) {
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.char
var j = 0, i = s.length;
while (j<i && whitespace.indexOf(s.charA
j++;
}
s = s.substring(j, i);
}
return s;
}
function RTrim(str) {
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.char
var i = s.length-1;
while (i>=0 && whitespace.indexOf(s.charA
i--;
}
s = s.substring(0, i+1);
}
return s;
}
function Trim(str) {
return LTrim(RTrim(str));
}
myString = "hello world ";
trace(myString);
Trim(myString);
trace(str);
The str trace comes back as undefined. Is there something wrong with the syntax? Any other suggestions for a trim function?
TIA,
Terry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help!
ASKER