# Split with "|" instead of "&"

**URL:** <https://forum.kirupa.com/t/split-with-instead-of/29362>\
**Category:** flash\
**Created:** [August 26, 2003, 12:37am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362 "2003-08-26T00:37:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waffe](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@waffe](https://forum.kirupa.com/u/waffe)\
**Post date:** [August 26, 2003, 12:37am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/1 "2003-08-26T00:37:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 12:50am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/2 "2003-08-26T00:50:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 12:54am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/3 "2003-08-26T00:54:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 12:55am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/4 "2003-08-26T00:55:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 12:59am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/5 "2003-08-26T00:59:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 1:13am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/6 "2003-08-26T01:13:53Z")

</div>

loadVars object also has onData

```auto
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 */

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2003, 1:29am UTC](https://forum.kirupa.com/t/split-with-instead-of/29362/7 "2003-08-26T01:29:12Z")

</div>

Well boom! then, works like a charm.

Thanks.
