Trimming Whitespace : trim « String « Flash / Flex / ActionScript

Home
Flash / Flex / ActionScript
1.Animation
2.Array
3.Class
4.Data Type
5.Development
6.Function
7.Graphics
8.Language
9.Network
10.Regular Expressions
11.Statement
12.String
13.TextField
14.XML
Flash / Flex / ActionScript » String » trim 




Trimming Whitespace
 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var example:String = "\n\r\f\ta string\t\t\n\n";
        
        trace"this string value is: " + example + "<end>" );
        
        example = trimexample );
        
        trace"this string value is: " + example + "<end>" );
        
        tracetrim"\n  \r\ta string\t\t\n\n" "<end>" );


    }
    public static function isWhitespacech:String ):Boolean {
      return ch == '\r' || 
             ch == '\n' ||
             ch == '\f' || 
             ch == '\t' ||
             ch == ' '
    }
    
    public static function trimoriginal:String ):String {
    
      var characters:Array = original.split"" );
    
      for var i:int 0; i < characters.length; i++ ) {
        if isWhitespacecharacters[i] ) ) {
          characters.splicei, );
          i--;
        else {
          break;
        }
      }
      return characters.join("");
    }
  }
}

        














Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.