Macromedia flex 2 Manual

Page of 254
Using the SwitchSymbolFormatter class
211
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: 
Format string:
 “The Social Security number is: ###-##-####”
Input string:
 "123456789"
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 
The SwitchSymbolFormatter class creates the following output string from the Format and 
Input strings:
"The SocialSecurity number is: 123-45-6789"
You use the 
formatString
 property of the SwitchSymbolFormatter class to specify the format 
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("&");