function Flash does not have its own trim () function, only add one, the following is the function code var mys:string= "The front contains a full space \" \ "and ordinary space \" \ ", now remove them";
function Trim (mystring:string) {//filter before and after spaces
if (Mystring.indexof ("") ==-1 && Mystring.indexof ("") ==-1) {//If there is no space in the string to return directly
return myString;
}
var omystring:string=mystring; Save the original string.
Mystring=replace (MyString, "", ""); Replace full-width spaces with normal spaces for easy handling
Number of spaces at the start of the Var lblanknum:number=0;//
The number of spaces at the end of the Var rblanknum:number=0;//
Calculate the number of spaces from the start position
for (Var i:number=0;i<mystring.length;i++) {
if (Mystring.charat (i)!= "") {
Break
}else{
lblanknum++;
}
}
Calculates the number of spaces in the end position
For (Var i:number= (mystring.length-1); i>0;i--) {
if (Mystring.charat (i)!= "") {
Break
}else{
rblanknum++;
}
}
Return omystring.substring (Lblanknum, (Omystring.length-rblanknum));
}
function replace (s:string,o:string,n:string) {//character substitution functions replace s in O to n
return S=s.split (o). Join (n);
} Output PartThe original string: preceded by a full corner space "" and ordinary Space "", now remove them, after processing: The front contains a full corner space "" and ordinary Space "", now remove them
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.