ActionScript 3.0: How to use trim funtion in Flex application

In ActionScript 3.0, we cannot use the trim function on strings, that we love from PHP or JavaScript. The trim function is however available to us if we include StringUtil in our project with import mx.utils.StringUtil.

When we import StringUtil, we can trim any string with StringUtil.trim(string). I love trim function and I was glad to find it in ActionScript.

import mx.utils.StringUtil;

var myString:String = '  This string needs to be trimmed   ';
myString = StringUtil.trim(myString);
trace(myString);
//return's This string needs to be trimmed with no whitespace on the left or right side
Advertisements

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: