Split with "|" instead of "&"

I am reading data from a txt file using loadVars. By default my text file must have an ampersand starting the text file a variable that = the text content and an apersand ending the the text file.

like this

&text=the content&

I would like to use a different slipt symbol like the “|”. I know this can be done for arrays in flash but how about for reading textfiles?

you CAN but it would mean making parsing your loaded text quite a bit tougher, especially it theres a lot of text loaded

Basically, this means you’ll have to load the raw text, and parse it yourself using split() or some other splitting methods.

Well, there is not that much txt and there is only on field to parse out, so all together I on have two ampersands.

Please do tell

Well, you could use the XML object with the onData event to load the raw text, then simply parse it.

loadVars object also has onData

loader = new LoadVars();
loader.onData = function(rawText){
	// split raw text by divider adding
	// to a data variable (array)
	var data = rawText.split("|");
	// get any rid of empty array values
	// at the ends of the array
	if (data[0] == "") data.shift();
	if (data[data.length-1] == "") data.pop();
	// declare a new array to hold the 
	// variable - value pairs
	var variables = new Array();
	// loop through the data array and
	// assign the variables array by splitting
	// the data by = to get variables and values
	var i = data.length;
	while(i--) variables.unshift(data*.split("="));
	// loop through the variables array to physically
	// assign the values to the loadVars object
	i = variables.length;
	while(i--) this[variables*[0]] = variables*[1];
	// call the onLoad (if defined) with success true
	this.onLoad(true);
	
	
	// test variables
	trace(this.myVar1); // value1
	trace(this.myVar2); // value2
											   
}
loader.load("data.txt");

/* data text contents:

|myVar1=value1|myVar2=value2|

end data text contents */

Well boom! then, works like a charm.

Thanks.