...

View Full Version : prob in split and array process



0o_o0
02-27-2009, 04:31 AM
anyone have ideas how to solve this question?

myText.text: 1)www 200 23feb
2)www 303 24march

how to split "www", "200" and "23feb" into one column each of them.
then, how to make sure this split process also occur at "www 303 24march" and so on..

gnomeontherun
02-27-2009, 01:58 PM
var str:String = "www 200 23feb";
var results:Array = str.split(" ");

This puts the string pieces into an array, which can then be added to a table.

0o_o0
03-06-2009, 09:10 AM
yes.. thank you for reply,,
but, it only split at the first of the sentences...
how to make sure it also split at the next sentences also.. for example:
this is the text after uploaded to the system:

www 200 23feb
www 303 24march
www 200 23feb
www 303 27march
www 200 21feb
www 303 29march

i want the split process also occur at www 303 24march, www 200 23feb and so on automtically after click the button. my system only split at the first sentences..

hope u can help me..
thank you.

gnomeontherun
03-06-2009, 10:34 AM
The you have to make a loop to parse them all. Something like this should parse them into a multidimensional array for you to access however you need to display.


var strings = new Array();
strings[0] = "www 200 23feb";
strings[1] = "www 303 24march";
strings[2] = "www 200 23feb";
strings[3] = "www 303 27march";
strings[4] = "www 200 21feb";
strings[5] = "www 303 29march";

for (i=0;i<=strings.length;i++)
{
results[i] = strings[i].split(" "); //Saves array in an array
}

0o_o0
03-11-2009, 03:29 AM
can u check my code?
at bold sentences have error and it says expecting semicolon before left bracket..
i dont know what to do?
through this code, is it split myText.text into several categories?

private function applicationCompleteHandler():void
{
var stringToSplit:String = myText.text;
var result[i]:Array = stringToSplit[i].split(" ");
var Split:LogReader = new LogReader();

for (i=0;i<=stringToSplit.length;i++)
{
Split.ip = result[0];
Split.date = result[3] + result[4];
Split.method = result[5];
Split.info = result[6] + result[7];
Split.url = result[8];
}

sourceArray.push(Split);
ac.refresh();


}

thank you.

gnomeontherun
03-11-2009, 10:43 AM
You are using an array index identifier that doesn't exist (i).


private function applicationCompleteHandler():void
{
var stringToSplit:String = myText.text;
var result:Array = stringToSplit.split(" ");
var Split:LogReader = new LogReader();

for (i=0;i<=result.length;i++)
{
Split.ip = result[0];
Split.date = result[3] + result[4];
Split.method = result[5];
Split.info = result[6] + result[7];
Split.url = result[8];
}

sourceArray.push(Split);
ac.refresh();

}

I guess I don't understand what you are trying to do, except that this code doesn't seem to make sense to me. I made another change in the for loop, because otherwise it won't run correctly (.length is for number of entries in an array here). What format is the data really coming in as (exactly) and what do you want it to sort into?

0o_o0
03-12-2009, 02:48 AM
thank you for reply.
okey..
this is the example of text that need to be split into several categories after uploaded into the system:

0.50.143.237 - - [31/Oct/2008:11:09:24 +0800] "GET /login/login.php?op=logout HTTP/1.1" 302 3727 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17"

60.50.143.237 - - [31/Oct/2008:11:09:24 +0800] "GET /login/login.php?msj=You%20Have%20Been%20Forced%20to%20Logout HTTP/1.1" 200 3766 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17"

60.50.143.237 - - [31/Oct/2008:11:09:24 +0800] "GET /images/stylesheet.css HTTP/1.1" 200 1958 "http://www.bppk.gov.my/login/login.php?msj=You%20Have%20Been%20Forced%20to%20Logout" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17"

60.50.143.237 - - [31/Oct/2008:11:09:24 +0800] "GET /images/bg_main.gif HTTP/1.1" 200 869 "http://www.bppk.gov.my/images/stylesheet.css" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17"

usually the text is more longer than this..
the split divided only 5 categories:ip, date, method, info and url. that's why this code had been made:

var stringToSplit:String = myText.text;
var result:Array = stringToSplit.split(" ");
var Split:LogReader = new LogReader();
Split.ip = result[0];
Split.date = result[3] + result[4];
Split.method = result[5];
Split.info = result[6] + result[7];
Split.url = result[8];

and the package LogReader.as imported in the system made this process works.

my problem is how to make the split process also occur at the next ip address?
my coding only split at the first paragraph..
i want it split simultaneously at the whole paragraph at the text that had been uploaded into the system.
i hope my explanations is good enough to make u understand what is actually i am going to do..
i hope u can help me.
thank you.

gnomeontherun
03-12-2009, 12:14 PM
So you are reading a log, that makes this more tricky. Honestly I would employ a few techniques rather than just splitting the string. You can search a string if it contains "POST" or "GET" for example, you could get the text between [] as the date, and search based on what is between " marks. It would be more labor intensive and require stronger code, but would be a much better way. What if someone has a URL with a space in it? You would have errors I think the current way.

0o_o0
03-13-2009, 04:03 AM
yes. but the other features will implemented after the split process works at the whole paragraph..
the system actually also planned to should be have check box option to make the analyzer more easier to analyze log.
as i told before, it works splitting at the first paragraph and it shows that split by space is not be the problem.. and let be my supervisor think it about if have space in the url because he asks me to do it like this.;) but, i will ask him later.:)
however, i have problem in how to make the splitting process also splitting at the second and so on paragraphs simultaneously with the first paragraph..
i had try this before:

for each(var line:String in myText.text.split("\n"))

but its wont work!

do you have any ideas?

thank you.

gnomeontherun
03-13-2009, 11:45 AM
Two options, \r is actually the return character. the ascii code is also 13 for it.


myText.text.split(char(13));
myText.text.split("\r");

0o_o0
03-17-2009, 03:03 AM
i had try myText.text.split(char(13)) but have error..

#1180:call to a possibly undefined method char

how can i avoid this error?

and when i try myText.text.split("\r");
it still only split the first paragraph..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum