Solved

VB.NET - Break a block of text into "sub-blocks"

Posted on 2015-02-11
1
351 Views
Last Modified: 2015-02-11
I'm using VB.NET.

I have a block of text I've read from a file. In that block of text are "subblocks", which I need to process individually. In the example below, I would read that entire block from disc and I then need to work with each "subblock" that starts with the line "//STX12//" - so the first subblock would be lines 1 thru 43, the second would be lines 44 thru 49, and so on. I've tried using Split, but that doesn't work - my syntax wouldn't split the lines correctly:

Dim fil As New StreamReader(FileIn)
Dim file As String = fil.ReadToEnd
Dim files() As String = file.Split("//STX12//")

I also tried various flavors of the Split method, but could get none of those to work. Either they would return nothing, or they would return bits and pieces of the various lines - nothing I could work with.

Is there any way to divide those into "subblocks" without walking the entire text block line-by-line? I know how to do that, but there must be a better way ...

//STX12//830CATMF                                           SC
13MF CRTT Dir Global
14Z Z
15+00000000002C150306
15+00000000001D150317
15+00000000001D150416
15+00000000001D150513
15+00000000001D150528
15+00000000002D150617
15+00000000001D150715
15+00000000001D150730
15+00000000001D150813
15+00000000001D150828
15+00000000001D150910
15+00000000001D150925
15+00000000001D151013
15+00000000002D151021
15+00000000001D151117
15+00000000002D151125
15+00000000002D151215
15+00000000001D160105
15+00000000002D160118
15+00000000001D160128
15+00000000003D160203
15+00000000002D160226
15+00000000002D160311
15+00000000003D160323
15+00000000002D160411
15+00000000002D160422
15+00000000003D160504
15+00000000002D160524
15+00000000001D160606
15+00000000003D160617
15+00000000001D160705
15+00000000002D160719
15+00000000002D160802
15+00000000002D160817
15+00000000002D160901
15+00000000002D160916
15+00000000002D160930
17                        150513150828                     +00000000000004140930
18140930
19GENPaint spec : 1E4520C-B
//STX12//830MORTON      20150210064507 0411                            CAR
14Y Z
15+00000000028C150715
17                                                         +00000000000004150108
18150209
19DELSHIP NO MORE THAN  10 DAYS PRIOR TO SHIP DATE
//STX12//830MORTON      20150210064506 0411                            CAR
01050411                          SH150401151202150209HESO51218
14Y Z
15+00000000040C150401
15+00000000040C150422
15+00000000040C150722
15+00000000046C150729
15+00000000050D150930
15+00000000046D151202
17                                                         +00000000000004140924
18150209
19DELSHIP NO MORE THAN  10 DAYS PRIOR TO SHIP DATE
//STX12//830EAST PEORIA 20150210064507 44                              CAR
010544                            SH1502161803271502105550022470
15+00000000012C150216
15+00000000012D150305
15+00000000012D150325
15+00000000012D150423
15+00000000012D150514
15+00000000012D150604
15+00000000012D150625
15+00000000012D150730
15+00000000012D150820
15+00000000012D150910
15+00000000012D150924
15+00000000012D151022
15+00000000012D151029
15+00000000012D151123
15+00000000012D151210
15+00000000012D151222
15+00000000012D160121
15+00000000012D160204
15+00000000012D160224
15+00000000012D160310
15+00000000012D160322
15+00000000012D160407
15+00000000012D160427
15+00000000012D160512
15+00000000012D160525
15+00000000012D160616
15+00000000012D160623
15+00000000012D160714
15+00000000012D160811
15+00000000012D160825
15+00000000012D160915
15+00000000012D160929
15+00000000012D161020
15+00000000012D161027
15+00000000012D161115
15+00000000012D161208
15+00000000012D161222
15+00000000012D170119
15+00000000012D180327
17                        150625150305+00000000012035150121+00000000012004140915
18150121
//STX12//830EAST PEORIA 20150210064507 30                              CAR
15+00000000020D150224
15+00000000020D150506
15+00000000020D150722
15+00000000020D150825
15+00000000020D150923
15+00000000020D151014
15+00000000020D151029
15+00000000020D151120
15+00000000020D151211
15+00000000020D160111
15+00000000020D160127
15+00000000020D160217
15+00000000020D160302
15+00000000020D160322
15+00000000020D160406
15+00000000020D160427
15+00000000020D160518
15+00000000020D160601
15+00000000020D160622
15+00000000020D160706
15+00000000020D160817
15+00000000020D160830
15+00000000020D160921
15+00000000020D161011
15+00000000020D161025
15+00000000020D161114
15+00000000020D161129
15+00000000020D161221
15+00000000020D170118
17                        150506150224                     +00000000000004140915
18140915
//STX12//830JD2REL      15040172406    15040                           D16
18                              USD
19+0000000000000250D20150325
19+0000000000000250D20151026
19+0000000000000000D20160125
19+0000000000000250D20160223
2001+000000000000025005020140402
2002+000000000000051905120140224
21SI164250
21PK164250
//STX12//830JD2REL      15040172406    15040                           D16
18                              USD
19+0000000000000001C20150204
19+0000000000000125C20150216
19+0000000000000125C20150326
19+0000000000000000D20150722
19+0000000000000125D20150901
19+0000000000000000D20150909
19+0000000000000125D20150923
19+0000000000000000D20150930
19+0000000000000125D20151102
19+0000000000000125D20151119
19+0000000000000000D20151125
19+0000000000000125D20151210
19+0000000000000000D20151230
19+0000000000000125D20160120
19+0000000000000125D20160208
19+0000000000000000D20160215
19+0000000000000125D20160311
19+0000000000000000D20160401
19+0000000000000125D20160415
19+0000000000000000D20160422
2001+000000000000022805020150112
2002+000000000001482705120051223
21SI165425
21PK165425
//STX12//830JOLIET      20150210064506 0401                            CAR
15+00000000005C1502160
15+00000000016C1502230
15+00000000012D1502260
15+00000000006D1503050
15+00000000007D1503130
15+00000000004D1503230
15+00000000004D1503310
15+00000000012D1504130
15+00000000002D1504200
15+00000000008D1504270
15+00000000001D1505050
15+00000000003D1505120
15+00000000009D1505190
15+00000000004D1505290
15+00000000015D1506080
15+00000000008D1506290
15+00000000008D1507070
15+00000000001D1507140
15+00000000015D1507210
15+00000000004D1507290
15+00000000006D1508050
15+00000000013D1508130
15+00000000007D1508270
15+00000000001D1509070
15+00000000003D1509140
15+00000000009D1509210
15+00000000008D1509280
15+00000000008D1510050
15+00000000011D1510120
15+00000000008D1510230
15+00000000015D1512110
15+00000000001D1512230
15+00000000009D1601190
15+00000000011D1601270
15+00000000004D1602040
15+00000000001D1602110
17            150331150226150629150413+00000000014035141215+00000000019004140909
18150209
19DELSHIP NO MORE THAN   5 DAYS PRIOR TO SHIP DATE
//STX12//830JOLIET      20150210064506 0401                            CAR
14Y Z
15+00000000020C1502190
15+00000000016C1502270
15+00000000016C1503260
17                                    +00000000016035150122+00000000145004140402
18150209
19DELSHIP NO MORE THAN   5 DAYS PRIOR TO SHIP DATE

Open in new window

0
Comment
1 Comment
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 0 total points
ID: 40602825
Figured out how to do this:

            Dim fil As New StreamReader(FileIn)
            Dim file As String = fil.ReadToEnd
            Dim files() As String = Strings.Split(file, "//STX12//")

That worked perfectly, and split my big chunk of Text into the necessary sub-blocks. It did result in the first element in the array being empty, but I check for that before moving on to other processing.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now