Question

I have created an application that parses some text files and pulls out and sorts the information into a table

Here is a sample

NODE    DSP Name    BUS   IDENT   STATION         REF1                  REF2

nnn1_1  S|xxxx|A1   1      1        1             S|yyyyyyyyyy|A1       S|zzzzzzz|A1

mmm1_1  R|xxxx|A1   1      1        1             R|yyyyyyyyyy|A1       R|zzzzzzz|A1

xxx1_2  R|xxxx|A1   1      1        1             R|yyyyyyyyyy|A1       R|zzzzzzz|A1

yyy1_1  R|xxxx|A1   1      1        1             R|yyyyyyyyyy|A1       R|zzzzzzz|A1

I need to check 3 things

  1. That if in the DSP Name there is a S| that it has at least one corresponding R|
  2. That the corresponding R| have identical BUS, IDENT, STATION
  3. That REF1 and REF2 match names

I can sort of brute force my way through this pulling in the table one line at a time and building a list of all the (S|) and then once have that list search for the corresponding (R|)... I already have the these in a datatable at one point, as well as a CSV file

Is there a simpler way to do this? Like LINQ?

Was it helpful?

Solution

Here's something to get you started:

var dspStartsWithR = From row in myDataTable.Rows
                     Where (string)row("DSP Name").StartsWith("R|")
var dspStartsWithS = From row in myDataTable.Rows
                     Where (string)row("DSP Name").StartsWith("S|")

Once you get your results you're going to have to do some combination of Substring to strip out the characters you don't need, do comparisons, etc. My C# is rusty so sorry if the code isn't quite right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top