|
|
 |
| All Resources > Flash > Flash Tutorials > ACTIONSCRIPT TUTORIALS |
 |
|
|
Ltrim, Rtrim and Trim functions for flashby 19.5 Degrees
|
|
| |
|
views: 20378 | rating: 5/10 |
|
| |
// parameters:
// matter, string to be trimmed
// returns:
// string, whitespaces removed from left side.
function ltrim(matter) {
if ((matter.length>1) || (matter.length == 1 &&
matter.charCodeAt(0)>32 && matter.charCodeAt(0)<255)) {
i = 0;
while (i<matter.length &&
(matter.charCodeAt(i)<=32 || matter.charCodeAt(i)>=255)) {
i++;
}
matter = matter.substring(i);
} else {
matter = "";
}
return matter;
}
// parameters:
// matter, string to be trimmed
// returns:
// string, whitespaces removed from right side.
function rtrim(matter) {
if ((matter.length>1) || (matter.length == 1 &&
matter.charCodeAt(0)>32 && matter.charCodeAt(0)<255)) {
i = matter.length-1;
while (i>=0 && (matter.charCodeAt(i)<=32
|| matter.charCodeAt(i)>=255)) {
i--;
}
matter = matter.substring(0, i+1);
} else {
matter = "";
}
return matter;
}
// parameters:
// matter, string to be trimmed
// returns:
// string, whitespaces removed from both sides.
function trim(matter) {
return ltrim(rtrim(matter));
}
|
|
|
 |
|
|
 |
|
 |
Thanks posted by: Amit on: Feb 19, 08 1:01 am
I think this code is very useful for me...thanks once agin.
post reply | read replies (0)

Little Modification posted by: Tushar on: Jan 24, 08 9:01 am
function trimString(par_String:String):String {
var sReturn:String = "";
for (i=0; i<=par_String.length-1; i++) {
if (par_String.charAt(i)<>" ") {
sReturn = sReturn+par_String.charAt(i);
}
}
return sReturn;
}
post reply | read replies (0)

Other Solution posted by: Tushar on: Jan 24, 08 8:30 am
You can also use this......
function trimString(par_String:String):String {
var sReturn:String = "";
for (i=0; i<par_String.length-1; i++) {
if (par_String.charAt(i)<>" ") {
sReturn = sReturn+par_String.charAt(i);
}
}
return sReturn;
}
post reply | read replies (0)

Tnx posted by: Gx on: Dec 23, 07 10:52 am
Tnx m8
Just what I needed. Made something like this in the past but losy almost all my code in a HD crash. This really saved me some time
post reply | read replies (0)

Thanks a lot posted by: Elaijha on: Nov 11, 07 9:24 am
it really saved my time!
post reply | read replies (1)

 |
|