Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    prob in split and array process

    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..

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Code:
    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.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.

    Code:
    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
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You are using an array index identifier that doesn't exist (i).

    Code:
    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?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by 0o_o0; 03-12-2009 at 03:12 AM.

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Two options, \r is actually the return character. the ascii code is also 13 for it.
    Code:
    myText.text.split(char(13));
    myText.text.split("\r");
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..
    Last edited by 0o_o0; 03-17-2009 at 11:17 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •