Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 223

Programming actionscript 3.0
Table of Contents

Advertisement

Using String methods to normalize image titles
One of the design decisions for this application is that all the image titles are displayed using a
standard format, with the first letter of each word capitalized (except for a few words which
are commonly not capitalized in English titles). Rather than assume that the text file contains
properly formatted titles, the application formats the titles while they're being extracted from
the text file.
In the previous code listing, as part of extracting individual image metadata values, the
following line of code is used:
imageInfo.title = normalizeTitle(imageProperties[1]);
In that code, the image's title from the text file is passed through the
method before it is stored in the ImageInfo object:
private function normalizeTitle(title:String):String
{
var words:Array = title.split(" ");
var len:uint = words.length;
for(var i:uint; i < len; i++)
{
words[i] = capitalizeFirstLetter(words[i]);
}
return words.join(" ");
}
This method uses the
the space character), passes each word through the
then uses the Array class's
again.
method to divide the title into individual words (separated by
split()
method to combine the words back into a single string
join()
normalizeTitle()
capitalizeFirstLetter()
Example: ASCII Art
method, and
223

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents