User Guide

222 Working with Strings
The file uses a specific tab-delimited format. The first line (row) is a heading row. The
remaining lines contain the following data for each bitmap to be loaded:
The filename of the bitmap.
The display name of the bitmap.
The white-threshold and black-threshold values for the bitmaps. These are hex values
above which and below which a pixel is to be considered completely white or completely
black.
As soon as the application starts, the AsciiArtBuilder class loads and parses the contents of the
text file in order to create the “stack” of images that it will display, using the following code
from the AsciiArtBuilder classs
parseImageInfo() method:
var lines:Array = _imageInfoLoader.data.split("\n");
var numLines:uint = lines.length;
for (var i:uint = 1; i < numLines; i++)
{
var imageInfoRaw:String = lines[i];
...
if (imageInfoRaw.length > 0)
{
// Create a new image info record and add it to the array of image info.
var imageInfo:ImageInfo = new ImageInfo();
// Split the current line into values (separated by tab (\t)
// characters) and extract the individual properties:
var imageProperties:Array = imageInfoRaw.split("\t");
imageInfo.fileName = imageProperties[0];
imageInfo.title = normalizeTitle(imageProperties[1]);
imageInfo.whiteThreshold = parseInt(imageProperties[2], 16);
imageInfo.blackThreshold = parseInt(imageProperties[3], 16);
result.push(imageInfo);
}
}
The entire contents of the text file are contained in a single String instance, the
_imageInfoLoader.data property. Using the split() method with the newline character
(
"\n") as a parameter, the String instance is divided into an Array (lines) whose elements are
the individual lines of the text file. Next, the code uses a loop to work with each of the lines
(except the first, because it contains only headers rather than actual content). Inside the loop,
the
split() method is used once again to divide the contents of the single line into a set of
values (the Array object named
imageProperties). The parameter used with the split()
method in this case is the tab (
"\t") character, because the values in each line are delineated
by tab characters.