-1

For the calculation of two lines, I need a search function that prints the first and the last line that begins with B.

I have a file that looks like this and need the number after the B, because that is a second. I want to calculate the second span between.

I'm sorry for the bad English.

Start File
AXCT XCTrack 0.6.0 - translations: 2017-03-14 17:49:58 on HUAWEI GEM-702L 6.0
HPPLTPILOT:Kay Starkermann
HOSITSite:Schwängimatt
HPCCLCOMPETITION CLASS:FAI-3 (PG)
HPGTYGLIDERTYPE:SKYWALK Spice
HODTM100GPSDATUM:WGS-84
HFALG:GEO
HFDTE060417
LXCTDEVICE eyJjYXBhYmlsaXRpZXMiOnsibWVtQ2xhc3MiOjI1NiwibWVtTGFyZ2VDbGFzcyI6M
LXCTDEVICE jU2LCJuYW4iOnRydWV9LCJkZXZpY2UiOnsiYW5kcm9pZElkIjoiMzRhM2Q1MzBhZm
LXCTDEVICE I4YmViYyIsImJvYXJkIjoiR0VNLTcwMkwiLCJidWlsZElkIjoiSFVBV0VJR0VNLTc
LXCTDEVICE wMkwiLCJjcHVBQkkiOiJhcm02NC12OGEiLCJjcHVBQkkyIjoiIiwiZGV2aWNlU3Ry
LXCTDEVICE aW5nIjoiSFVBV0VJIEdFTS03MDJMIDYuMCIsImRpc3BsYXkiOnsiaCI6MTg0OCwib
LXCTDEVICE W0iOjE1Ljc0ODAzMiwidyI6MTIwMH0sImZpbmdlcnByaW50IjoiSFVBV0VJL0dFTS
LXCTDEVICE 03MDJML0hXR2VtaW5pOjYuMC9IVUFXRUlHRU0tNzAyTC9DMjA5QjIwMzp1c2VyL3J
LXCTDEVICE lbGVhc2Uta2V5cyIsImhhcmR3YXJlIjoiaGkzNjM1IiwibWFudWZhY3R1cmVyIjoi
LXCTDEVICE SFVBV0VJIiwicHJvZHVjdCI6IkdFTS03MDJMIiwic2RrIjoyM30sInhjdHJhY2siO
LXCTDEVICE nsidmVyc2lvbkNvZGUiOjYzLCJ2ZXJzaW9uTmFtZSI6IjAuNi4wIC0gdHJhbnNsYX
LXCTDEVICE Rpb25zOiAyMDE3LTAzLTE0IDE3OjQ5OjU4In19
LXCTSENSOR Sensors: SENSOR_BT, external GPS:true, external baro:true, intern
LXCTSENSOR al baro:false
LXCTEARTHMODEL FAI_SPHERE
B1505404717336N00740471EA0101001091
B1505414717336N00740472EA0101001091
B1505424717335N00740472EA0101001091
B1505434717336N00740472EA0101001090
B1505444717336N00740472EA0100901090
B1505454717336N00740471EA0100901091
B1505464717336N00740471EA0101001091
B1505474717336N00740471EA0101001091
B1505484717336N00740471EA0101001091
B1505494717336N00740471EA0101001091
B1505504717336N00740471EA0101001091
B1505514717336N00740471EA0101001091
End File
toonice
  • 2,211
  • 1
  • 13
  • 20
Nero8Eye
  • 11
  • 2
  • Have you tried reading the file line by line yet? Are those "B" values each on their own line?...with the line actually starting with "B"? Will they always be contiguous with no other lines inbetween? etc... – Idle_Mind Apr 07 '17 at 00:44

2 Answers2

0

UPDATE: I've modified the answer since you clarified the file format

You could try a regular expression that matches a word that begins with a 'B' and is followed by alpha-numeric characters. I'm not great with them, but this seems to do the trick:

var matches = Regex.Matches(input, @"([B][0-9][A-Za-z0-9]\w+)");

// This says find all matches that:
//    [B]          :  starts with the letter 'B'
//    [0-9]        :  followed by a number
//    [A-Za-z0-9]  :  followed by any alpha-numeric characters
//    \w+          :  and get the whole word

Here's one way to use it:

var input = File.ReadAllText(filePath);

var matches = Regex.Matches(input, @"([B][0-9][A-Za-z0-9]\w+)");

foreach(var match in matches)
{
    Console.WriteLine(match);
}

Output:

enter image description here

Rufus L
  • 36,127
  • 5
  • 30
  • 43
0

Regex is a great way to read through a file, capturing the information you need and then store in a list.

MatchCollection matchList = Regex.Matches(Content, Pattern);
var list = matchList.Cast<Match>().Select(match => match.Value).ToList();

I found this here which shows how you would use Regex to capture the information and store in a list.

Put together a quick pattern which makes the assumption that the length is always the same.

B(?<Seconds>[\d\w]{34})\s

You can find a test here

To then get the first and last match, it is simply accessing the first and last item in the list.

An example can be found here.

Community
  • 1
  • 1
Troy Poulter
  • 677
  • 1
  • 8
  • 29