Your data is not actually column based - it’s a fixed position flat file (and btw line endings are a mess @_@).
There is another way (among many many others which you could do it):
- Read all lines
- Skip while not in correct section
- Skip some more until in actual table
- For non-empty lines check for CP in fixed position, store it
- In the same iteration check for firm number in fixed position, concatenate with CP and store in a list
You may want to expand a little on the positions, your sample dataset has very few entries and thus is not reliable.
Sample below, just for reference.
TextParseTest.xaml (10.2 KB)
@sankar.kuna - your point 4 is incorrect, see lines 59 & 64 in the sample file. They start with numbers, but the values needed are not present.
Also in most cases checking for “Is it a String” is like not checking at all - from text file perspective, everything is a string (even an empty line = String.Empty = String).
Your solution also creates a lot of additional memory allocations (every split produces a new array of strings). For big files that can be an issue. It’s usually better to read once and iterate forward (let’s leave streamreaders aside in Rookies section) - string operations on todays CPU’s are for the most part fast enough that extra calculations take less time than allocations (and you don’t risk OOM).