[Flash Development Notes] customize the trim function in ActionScript, retrieve the car function, and convert bytes.

Source: Internet
Author: User
We know that vbs has a trim function, which is used to remove spaces at both ends of a string. As is not available, we can customize:

// Removes leading and trailing spaces of a string.
Function Trim (returnstring) {
For (; Returnstring. charcodeat ( 0 ) =   0x20 ; Returnstring = Returnstring. substr ( 1 )) {
}
For (; Returnstring. charcodeat (returnstring. Length - 1 ) =   0x20 ; Returnstring = Returnstring. substr ( 0 , Returnstring. Length - 1 )) {
}
Return Returnstring;
}

// Return the front and back of the string
Public static Function Trimenter (returnstring) {
For (; Returnstring. substr ( 0 , 1 ) = String. fromcharcode ( 13 ); Returnstring = Returnstring. substr ( 1 )) {
}
For (; Returnstring. substr (returnstring. Length - 1 , 1 ) = String. fromcharcode ( 13 ); Returnstring = Returnstring. substr ( 0 , Returnstring. Length - 1 )) {
}
Return Returnstring;
}

This is also commonly used: // Byte conversion kb, MB
Function Getsizetype (size: Number) {
If (Size < 1024 ) {
Return Int(Size*100)/100+"Bytes";
}
If (Size < 1048576 ) {
Return Int(Size/1024)*100)/100+"KB";
}
If (Size < 1073741824 ) {
Return Int(Size/1048576)*100)/100+"MB";
}
Return   Int (Size / 1073741824 ) * 100 ) / 100 + " GB " ;
}

Verify that the entered content is a number:If(Isnan("Content to be verified")= True){
Trace("A non-number is entered");
}Else{
Trace("Number entered");
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.