Return to Snippet

Revision: 44603
at April 14, 2011 21:42 by robslegtenhorst


Initial Code
// FileStream object used to open the file
var _fs : FileStream;
// RegExp to search for the characters tag
var _pickRegExp : RegExp = /<characters>(.*)<\/characters>/g;
// Array used to store the strings found
var tempArray : Array = [];

// loop through all the files in the Array
for each (var $file : File in $fileArr)
{
	// close the FileStream if it exists
	if (_fs != null) _fs.close();
		
		_fs = new FileStream();

		// open the file and read it's data, then close it again
		_fs.open($file, FileMode.READ);
		var data : String = _fs.readUTFBytes(_fs.bytesAvailable);
		_fs.close();
		
		// search through the data using the RegExp
		var result : Object = _pickRegExp.exec(data);
		
		// as long as there are results found the RegExp keeps searching
		while (result != null)
		{
			tempArray.push(result[1]);
			result = _pickRegExp.exec(data);
		}
	}
}

// returns a clean Array, cleared of all duplicates
return clearDuplicates(tempArray);

// function used to clear all duplicates from the array using the Dictionary Class (http://livedocs.adobe.com/Flash/9.0/ActionScriptLangRefV3/Flash/utils/Dictionary.html)
function clearDuplicates($arr : Array) : Array
{
	var dict : Dictionary = new Dictionary(true);
	var output : Array = new Array();
	var item : *;
	var total : int = $arr.length;
	var pointer : int = 0;
	for (pointer; pointer < total ; pointer++)
	{
		item = $arr[pointer];
		if (dict[item] == undefined)
		{
			output.push(item);
			dict[item] = true;
		}
	}
	
	output.sort();
	
	return output;
}

Initial URL

                                

Initial Description

                                

Initial Title
AIR file search and replace

Initial Tags
search, replace

Initial Language
ActionScript