hi!
i'm new to the C#. net and need a help for my application, thanks in advance,problem is i have an application which has to read the data which is like this
-------------------------(white spaces which is in the file)
--------- abc ---------- d----------- efd----------- de
If yes, you can use the starting column index for each item to extract the values. Read the first x characters from index y of the row. Trim the result and if it's an empty string, the field you put into the database is null. If the values don't start on the same column, you have a problem because there might not be a way to know which fields are null and which fields aren't if there aren't four values for each name...
Last edited by Hamrick; Aug 22nd, 2007 at 12:11 pm.
This looks like a recipe for disaster. You need to think of a better(more unique) way to identify each column. Counting white space just ain't gonna cut it.
This looks like a recipe for disaster. You need to think of a better(more unique) way to identify each column. Counting white space just ain't gonna cut it.
It's not counting whitespace, it's relying on a fixed width column format. There's no way to identify empty fields in the sample that dineshsachdeva gave. But if the first field always starts at column 11, the second field always starts at column 21, the third field always starts at column 31, and the fourth field always starts at column 41, that's a completely unique way of identifying each column. There's no recipe for disaster unless the file format isn't really fixed width.
In fact, this is exactly what I did to parse and reformat some reports for a local wholesaler. The column widths were always the same and the company is still using the report filters to this day without any problems. If dineshsachdeva's file isn't fixed width, this won't work, but neither will anything else that I can think of because there's no way to tell if there's an empty field in between one field and the next.
And he never said he's using fixed width column if you reread the original thread so you are making assumptions.
I did nothing of the sort. Read my first post again and you'll see that I asked about the format of the file and on the off chance that it's fixed, I offered a suggestion.
Quote ...
There are much easier ways to do this, (much more flexible too) I'm afraid.
Nobody learns if you keep those much easier and more flexible ways to yourself.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.