943,548 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1039
  • C# RSS
Aug 22nd, 2007
0

Need a help

Expand Post »
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:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dineshsachdeva is offline Offline
1 posts
since Aug 2007
Aug 22nd, 2007
0

Re: Need a help

Is the spacing consistent in the file? Like do each of the values always start at the same column?
C# Syntax (Toggle Plain Text)
  1. abc d efd de
  2. xxx 25.80 12.10 180000.0 11111
  3. yyyyyyyy 709. .03
  4. 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...
Last edited by Hamrick; Aug 22nd, 2007 at 12:11 pm.
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 22nd, 2007
0

Re: Need a help

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 22nd, 2007
-1

Re: Need a help

Quote ...
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.
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 22nd, 2007
-1

Re: Need a help

> 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.
Last edited by iamthwee; Aug 22nd, 2007 at 4:37 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 22nd, 2007
0

Re: Need a help

Quote ...
Nah, that is just stupid.
I disagree, and I challenge you to prove it.

Quote ...
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.
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007

This thread is more than three months old

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.
Message:
Previous Thread in C# Forum Timeline: Select Random Number from Access Table Using C#
Next Thread in C# Forum Timeline: MS SQL server 2005 Express Edition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC