tags:

views:

465

answers:

4

Parsing a text file in vb.net and need to locate the latitude and longitude in these two sections of text. The patter is 6 digits space 7 digits (364800 0953600). The samples are from two different map files and have slightly differing formats.

I 2H02 364800 0953600 '                 SEC72                           10496300-
I 2H05 360100 0953645 '                               ZFW J602 ZME 2A93 10496400-
I 2H06 361215 0952400 '                 SEC72                  ZME 2A75 10496500-
I 2H07 361715 0951145 '                 SEC27/72               ZME 2A78 10496600-
I 2H08 362025 0950100 '                 TUL                    ZME 2A69 10496700-
I 2H10 360800 0952915 '                                        ZME 2A85 10496800-
I 2H11 362500 0955015 '                 SEC62/72                        10496900-
I 2H14 364145 0954315 '                 TUL                             10497000-


I A85A                  'AL851                                50591 REF 33393944 
         391500 0831100 '                                     50591 REF 33393945 
I A85B                  'AL851                                50591 REF 33393946 
         374500 0825700 '                                     50591 REF 33393947 
I A87A                  'AL871                               111592 REF 33393948 
         402050 0814420 '                                    111592 REF 33393949 
I A87B                  'AL871                               111592 REF 33393950 
         400449 0814400 '                                    111592 REF 33393951 
I A87C                  'AL872                              '030394 GDK 33393952 
         392000 0810000 '                                   '030394 GDK 33393953

Thanks,

Dave

A: 

Do a simple group capture. It appears your RegEx formula will be simple enough to handle both scenarios (be a little lose on the space detection). Then you can access the group properties of the match (either named or just basic index) and get the data you need.

Dillie-O
+6  A: 

A simple regex should do it:

[0-9]{6} [0-9]{7}
Joel Coehoorn
+2  A: 

.....

(?<First>\d{6})\s(?<Second>\d{7})
Quintin Robinson
+6  A: 
Dim matches As MatchCollection
Dim regex As New Regex("\d{6} \d{7}")
matches = regex.Matches(your_text_string)
Aaron Palmer
I saw something recently where \d doesn't always work as well in unicode environments, so be careful with it.
Joel Coehoorn
Interesting. I didn't know that... safest bet would be [0-9] then.
Aaron Palmer