Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Best way to use delimiter/other options

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Best way to use delimiter/other options

    So I have a file that the program will read. In it, it reads the latest line of a file. The line looks like this:
    09:28:04 Play      1  C48-6         What's The Altitude f. Hymnal  Cut Chemist           MUA D0291

    If I need each of these as a separate variable (or to simply ignore one, i.e. C48-6), what would be the best option to separate these? Would it be as simple as a multi-space delimiter for the scanner?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Best way to use delimiter/other options

    How much do you know about the file? What I mean is, the following questions:
    In reference to 09:28:04, will it always be 2 digits colon 2 digits colon 2 digits?
    Followed by a single space and the word Play, several spaces and a numerical value...etc Will the count of spaces always be the same?
    Will the MUA always be a 3 character code?
    If you know specific things about the text file that will never change you can use what you know to help pick out what you want.

    Don't forget you can traverse the string from the right hand side moving left also. You could grab D0291 off the end of the string by walking left until the first space, for example.

  3. The Following User Says Thank You to jps For This Useful Post:

    iceraven721 (April 18th, 2013)

  4. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Best way to use delimiter/other options

     08:47:27 Play      1  F1062-5       Kiss With a Fist               Florence and the Mach MUA D0271          
     08:49:25 Play      5  PSA0          Turning Point                  Mikey                 PSA D0272          
     08:49:52 Play      6  J1003-3       Nonsense                       Jimi Austin, The (Loc MUG D0273          
     08:54:50 Play      4  A1094-4       Criminals                      Atlas Sound           MUA D0274          
     08:57:41 Goto                       11:59:50 GTL Simple           UPDATE                     D0276          
     08:57:41 Play      2  LSC_ROTATING  Consturction - LSC Legal ID    Mikey                 BUM D0277          
     08:57:50 Play      3  E26-2         Dirty Girl                     Eels(Live at Town Hal MUA D0278          
     09:00:43 Play      1  V1054-1       I Can't Breathe                VTG                   MUS D0279          
     09:04:20 Play      5  NIB00NEW06    Personality - DJ Noah          Mikey/Cheyenne        BUM D0280          
     09:04:21 Play      6  P1281-5       Tragedy's A'Comin'             Primus                MUS D0281          
     09:09:07 Play      4  X2-9          Save Me Save Me                Xiu Xiu               MUS D0282          
     09:11:42 Play      2  NIB00NEW06    Personality - DJ Noah          Mikey/Cheyenne        BUM D0283          
     09:11:44 Play      3  M1225-2       The Kids Were Wrong            Memoryhouse           MUG D0284          
     09:15:49 Play      1  M170-2        Boyz                           M.I.A.                MUG D0285          
     09:19:07 Play      5  NIB00NEW06    Personality - Chipper and Abfab Mikey/Arthur/Abby    BUM D0286          
     09:19:15 Play      6  S58-11        Ocean Breathes Salty           Sun Kil Moon(Modest M MUS D0287          
    -09:23:42 Play      2  N1030-1       NO FILE [Brain Burner                   NO AGE]      MUS D0288          
     09:23:47 Play      4  NIB00NEW06    Legal - Harbinger              Dylan/Dale            BUM D0289          
     09:23:50 Play      3  J1075-2       Gorilla Meat                   Jogger                MUG D0290          
     09:28:04 Play      1  C48-6         What's The Altitude f. Hymnal  Cut Chemist           MUA D0291
    The file stays relatively consistent throughout. This is a log file for a radio station automation system. Essentially how I have it laid out is that every couple of minutes the program will check the file. If the last line is the same as when it checked before, then it will do nothing. But if it is different, it will take the song name and artist from the center and update them in a SQL database. I'm just trying to sort out how I can extract those names.

    The beginnings of the song and artist are almost exact on every song. Maybe an option to begin the scan at a character count?

    (I will have to add some ignore cases for if it is not a song, or if there is a "NO FILE". But that will come later.)

  5. #4
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Best way to use delimiter/other options

    What have you tried so far? Any code to show us?

  6. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Best way to use delimiter/other options

    I've gotten the initial scan import and string set up. I have a few ideas for splitting it up using characters. I'll try them and see if it works

  7. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Best way to use delimiter/other options

    Quote Originally Posted by iceraven721 View Post
    The file stays relatively consistent throughout .... almost exact on every song...
    Relatively consistent and almost exact are not good enough for a program to count characters.

    The 5th and 15th lines of the sample posted show problems.
    UPDATE starts one character too soon on the 5th line.
    Abfab runs over and pushes Mikey over on the 15th line. Also note that this causes just a single space between the two. How can the computer decide the song name has ended and the artist has started?
    I'm not saying it can't be done, but from a performance perspective it would be much better to start with a properly formatted log file.

    You will just have to establish a set of filtering rules based on the rules that are used when the log file was built. Which, again, would be much easier if the log file was consistent.

  8. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Best way to use delimiter/other options

    Luckily these inconsistencies are in other categories other than ones I need. My first task is to check if that line matches the 3 letter code in looking for.

  9. #8
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Best way to use delimiter/other options

    How are you grabbing the last line of the log file? I presume the file is quite large, or may become so.

  10. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Best way to use delimiter/other options

    I've got it so that it tracks down the file till it hits the last line. I'm looking around for a simpler way to do it. Maybe a length call?

    while(scan.hasNextLine()){
    			lastline = scan.nextLine();
    		}

Similar Threads

  1. delimiter problem
    By kyanamgoutham in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 8th, 2012, 11:25 AM
  2. Having trouble getting started testing for matching delimiter sets.
    By orbin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 5th, 2012, 01:48 PM
  3. Scanner delimiter
    By NoviceJAVA in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2011, 06:44 PM
  4. use Delimiter, Scanner Class
    By izzahmed in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 25th, 2011, 05:27 PM
  5. delimiter question
    By Sterzerkmode in forum Java SE APIs
    Replies: 1
    Last Post: November 19th, 2009, 06:21 AM