Tag Archives: join()

Trimming strings using the Flex StringUtil class’s trimArrayElements() method

The following example shows how you can remove leading and trailing spaces from an Array using the Flex StringUtil class’s trimArrayElements() method.

Similar to my earlier post, “Trimming strings using the Flex StringUtil class’s trim() method“, the StringUtil class has another rediculously handy method, trimArrayElements().

Essentially, this method allows you to trim leading and trailing whitespace from every element an array with one single method call, rather than having to resort to awkward loops and variable reassignments. The only real “gotcha” is that this method expects a string as a parameter and return value instead of an Array object.

Sayeth the docs:

public static function trimArrayElements(value:String, delimiter:String):String {...}
Removes all whitespace characters from the beginning and end of each element in an Array, where the Array is stored as a String.

Full code after the jump.

Continue reading Trimming strings using the Flex StringUtil class’s trimArrayElements() method