Transfer messy text file to datagrid
Hi,
I'm working on a small utility for my employer whereby I need to read in the contents of a text file, put it into a datagrid, and sum the totals for two of the columns.
I've had a quick look around, and all I keep on finding is reference to the 'split' command.
The problem is that there are no definitive splits in the text file.
The source text file is really messy, but it does have a structure that I hope I can work with. I have worked out that the lines I need to import all begin with a single character, "K". The columns (on these lines beginning with "K") that I need to import and work with, for example, start on character number 8, which references a product code, and is (for example) 8 characters in length. The next 'column' of information starts on character number 20, and is a numeric value covering 10 chars. Immediately after this 'column' (no spaces in between!) is another numeric value - again 10 characters in length.
What I want to do is put this data into a datagrid, and sum the numeric columns.
Any help would be appreciated.
Re: Transfer messy text file to datagrid
If the columns you need are always in the same position in the relevant lines then you can just read each line until you find a K then break that line up using substrings, starting at the position of the item you want and reading for x number of characters and so-on.