A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Triming the variable?

  1. #1
    Senior Member
    Join Date
    Dec 2000
    Posts
    107
    I wanted to trim the varible for any leading and trailing empty spaces i.e if somebody enters a variable in the dynamic text box ,i should be able to remove the blank spaces in the beginng or the end.Is their any inbulit function in flash for triming?(like TRIM in ASP)If not how can i go about making this function i mean do i need to check each word...how?

  2. #2

    Post

    Try this:

    Code:
    function trim(str) {
    	var s=0;
    	var e=str.length;
    	while (str.charAt(s)==" ") {
    		s++;
    	}
    	while (str.charAt(e-1)==" ") {
    		e--;
    	}
    	return(str.substring(s,e));
    }
    
    trace("!" + trim("    THIS SHOULD WORK    ") + "!");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center