Category Archives: StringUtil

Checking whether a color name is a valid color in Flex using the StyleManager class

The following example shows how to use the static StyleManager.isColorName() method to check whether a color name is valid or not. This method takes a single parameter, colorName, and returns a Boolean value representing whether the parameter is a valid alias for a color.

Full code after the jump.

Continue reading Checking whether a color name is a valid color in Flex using the StyleManager class

Checking if a character is whitespace using the Flex StringUtil class’s isWhitespace() method

The following example shows how you can check whether a character is a whitespace character by using the isWhitespace() method in the mx.utils.StringUtil class. And just for giggles, I also show how you can do the same thing using regular expressions (RegExp) with POSIX character classes.

Full code after the jump.

Continue reading Checking if a character is whitespace using the Flex StringUtil class’s isWhitespace() method

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

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

The following example shows you how to use the StringUtil.trim() method in Flex to remove leading and trailing whitespace from form fields before validating user input. This allows you to make sure that user’s don’t try anything sneaky like enter spaces instead of characters to bypass any minimum length validation you may have in place when validating data.

Full code after the jump.

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

Converting color names to numbers using the StyleManager class

The following examples show how you can convert color names (such as “red”, “haloSilver”, “#FFFFFF”, and “0xFFFF00”) into numeric values, using the StyleManager class’s static getColorName() method and getColorNames() method.

Full code after the jump.

Continue reading Converting color names to numbers using the StyleManager class