6 Replies Latest reply: Dec 13, 2013 8:56 AM by user8749582 RSS

    Extracting multiple variables of different fixed length from a string ( Java )

    learningoracle

      Dear all,

       

      I am expecting an input string of

       

      NationalBroadCastTony12245tv0930113024213tv0820230022214tv0915140024213rd10002300

       

      I need to display it in the following format:

       

      Telecastor: NationalBroadCast

      Presenter:Tony

      ch_codepg_codesourcestart_timeend_time
      12245tv09301130
      24213tv08202300
      22214tv09151400
      24213rd10002300

       

      I know the starting and ending position of Telecastor, and Presenter in the input string. I also know the position of the start element of the table(starting of the loop). I also know the length of a single row( allows me to contruct the loop). I reckon regex is probably not the best way since there is no pattern matching. I am looking at some sort of a config driven logic.

       

      Are there any java string function that I can use together with some form of config driven configuration that anyone can suggest?

       

      I am looking along the line of some configuration like eg

      telecastor 17

      Presentor  4

      pg_code 4 ( anything after character 21 is the loop)

      source 2

      start_time 4

      end_time 4

       

      For example another input I can expect is

       

      ElementaryScienceAccessment223-Feb-131500-1730RegentHallE32344390E21235487A23443564G23443246

       

      I need to display as

      Exam:ElementaryScience

      Nature: Accessment2

      Date:23-Feb-13

      Time:1500-1730

      Venue:RegentHall

      Student IDScore
      E32344390
      E21235487
      A23443564
      G23443246

       

      Exam:17

      Nature:11

      Date:9

      Time:9

      Venue:10

      Student ID:7 (anything after 56 is a loop)

      Score:2

       

      Unfortunately the input stream is not in XML format. What sort of string function/config driven logic can I use to allow me to define a 1 config fits all mechanism?