Read the data from .txt file

datatable
text
file

#1

I want to check if there is any error under "LIST OF RECEIVED ERRONEOUS FILES " .If there is any error then
i have to copy the data from “CP/FIRM” column and store and display it, if number is not there then skip

in the sample file attached under “LIST OF RECEIVED ERRONEOUS FILES” there are BP 777 ,BP 877,SP 556,SP87 we need these numbers from text file . and these numbers are dynamic

sample.zip (810 Bytes)


#2

Here I can suggest you the logic to do it…

  1. Split Based on the Text " LIST OF RECEIVED ERRONEOUS FILES "
  2. Consider 2nd Part of it…and Split again based on text " CCD CP/FIRM FILE NON-NO DATE TIME NUM ERROR FILE MESSAGE"
    Now u will get the targeted text
  3. Split Based on “New Line”(Environment.NewLine)
  4. Checke each line wthether it is starting with String or Int
    if string "Split again based on “Space” and consider 2nd , 3rd strings
    if int Consider directly and add the privious BP or SP

It gives you the final required text…

Hope it helps… Plz revert with response :slight_smile::slight_smile:


#3

Thank you. i will try the process which u told


#4

Is there any way other to do the same?


#5

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):

  1. Read all lines
  2. Skip while not in correct section
  3. Skip some more until in actual table
  4. For non-empty lines check for CP in fixed position, store it
  5. 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).


#6

thanks @andrzej.kniola :slight_smile: