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

xxx----- 25.80---------12.10--------180000.0--------11111

yyyyyyyy---------------709.-----------.03-------------------

zz-------------------------------------1426.-------------------------

and has to make an entry in the database in a table as
table structure is name, abc , d, efd, de

first entry should be

name: xxx
abc:25.80
d:12.10
efd:180000.0
de:11111

second entry should be

name: yyyyyyyy
abc:
d:709.
efd:.03
de:

second entry should be

name: zz
abc:
d:
efd:.1426.
de:

Is the spacing consistent in the file? Like do each of the values always start at the same column?

abc       d         efd       de
xxx       25.80     12.10     180000.0  11111
yyyyyyyy            709.      .03
zz                  1426.

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...

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.

Comments
Poor advice, I'm afraid.

> It's not counting whitespace, it's relying on a fixed width column format.

Nah, that is just stupid. And he never said he's using fixed width column if you reread the original thread so you are making assumptions.

There are much easier ways to do this, (much more flexible too) I'm afraid.

Comments
if you can't offer anything constructive, don't post

Nah, that is just stupid.

I disagree, and I challenge you to prove it.

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.

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. :angry:

This article has been dead for over six months. Start a new discussion instead.