parsing - Parse Text File with Variable Fields Vb.Net -


The way I am processing, it changes the way the data is formatted, so at that time It is time to update which it parses the old file had a fixed number of lines and per record field and hence it was easy to parse it from the position, definitely this is not the case now (I add spaces for readability Taken, ~ a new line , * Is field separator):

~ ENT * 1 * 2J * 34 * 111223333
~ NM1 * IL * 1 * Smith John A *** N * 123456789

RMR ike H62XX / PAY / 1234567/20150103 ** 12345.67

REF ZZ MEDPM / M / 12345.67

REF * LU * 40 / CSWI
~ DTM * 582 **** RD 8 * 20150101-20150131

~ ENT * 2 * 2J * 34 * 222334444
NM1 * IL * 1 * DO Jane S *** N * 234567891
RMR IC H62XX / PAE / 1234567/345678 901 ** 23456.78
~ REF * AUEUU 40 / CSWi ~ DTM * 582 * *** RD8 * 20141211-20141231

~ ENT * 3 * 2J * 34 * 333445555
NM1 * IL * 1 * DOE * John **** N * 345 678 9012

RMR IK H62XX / PAY / 200462975/20150103 ** 45678.90

REF ZZ MEDPM / M / 3456.78

REF * LU * 40 / CSWI

DTM * 582 **** RD 8 * 20150101-20150131

~ ENT * 4 * 2J * 34 * 444556666
~ Nm1 * IL * 1 * Smith Jane D *** N * 456789012

RMR ike HK 62XX / Pay / 567890123/678901234 ** 6789.01

REF < Em> ZZ MEDPM / M / 6789.01

REF * LU * 40 / CSWI

DTM * 582 **** RD8 * 20150101- 20150131

~ ENT * 5 * 2J * 34 * 666778888
NM1 * IL * 1 * Smith Zone J *** N * 8901234
~ RMR IK H62XX / PAY / 56789012/67891212 ** 5678.90

REF ZZ MEDPM / M / 5678.90

REF * LU * 40 / CSWI

DTM * 582 **** RD8 * 20150101-20150131

~ ENT * 6 * 2J * 34 * 77788 99 99

NM1 * IL * 1 * DO BOB E * ** N * 567890123
RMR IK HK 62XX / Pay / 34567890/45678 901 * 5678.90
~ REF * AULEU 40 / CSWI < Br> DTM * 582 **** RD8 * 20141210-20141231

RMR IC H62XX / PAY / 1234567890/2345678901 ** 6789.01

REF Z Z MEDPM / M / 6789.01

REF * LU * 40 / CSWI
~ DTM * 582 **** RD8 * 20150101-20150131

To parse this data What is the best way?

is your friend.

If the file is not very large, the simplest way would be to:

  • Read the file contents in a string variable ( File.ReadAllText ) .
  • Divide "line" ( lines = all text. Sample ("~" c) ).
  • For each row of loops through lines:
    • Divide the row into the field ( fields = line.Split ("*" c) ) < / Li>
    • Process field values ​​You might want to make a case statement on a large case and then proceed to the first field of the row. .

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -