Using The Switchsymbolformatter Class - Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

Using the SwitchSymbolFormatter class

You can use the
SwitchSymbolFormatter
utility class when you create custom formatters. You
use this class to replace placeholder characters in one string with numbers from a second
string.
For example, you specify the following information to the SwitchSymbolFormatter class:
"The Social Security number is: ###-##-####"
Format string:
"123456789"
Input string:
The SwitchSymbolFormatter class parses the format string and replaces each placeholder
character with a number from the input string in the order in which the numbers are specified
in the input string. The default placeholder character is the number sign (#). You can define a
different placeholder character by passing it to the constructor when you create a
SwitchSymbolFormatter object. For an example, see
"Using a different placeholder character"
on page
211.
The SwitchSymbolFormatter class creates the following output string from the Format and
Input strings:
"The SocialSecurity number is: 123-45-6789"
You use the
property of the SwitchSymbolFormatter class to specify the format
formatString
string. You can mix alphanumeric characters and placeholder characters in this format string.
The format string can contain any characters that are constant for all values of the numeric
portion of the string. However, the input string for formatting must be numeric.
The number of digits supplied in the source value must match the number of digits defined in
the format string. The code that calls the SwitchSymbolFormatter object verifies that the
number of digits match.
Using a different placeholder character
By default, the
SwitchSymbolFormatter
class uses a number sign (#) as the placeholder
character to indicate a number substitution within its format string. However, sometimes you
might want to include a number sign in your actual format string. Then, you must use a
different symbol to indicate a number substitution slot within the format string. You can
select any character for this alternative symbol as long as it doesn't appear in the format string.
For example, to use the ampersand character (&) as the placeholder, you create an instance of
the SwitchSymbolFormatter class as the following example shows:
var dataFormatter = new SwitchSymbolFormatter("&");
Using the SwitchSymbolFormatter class
211

Advertisement

Table of Contents
loading

Table of Contents