|
-
Apr 27th, 2009, 01:18 PM
#1
Thread Starter
Hyperactive Member
Arrays and Strings
I have been summoned with the task of taking a tab delimited file and converting that file so it can be read by a third-party program. I am trying to think of the best way to do this, but I am having a hard time. Here is a view of the raw data that must be altered:
Code:
fkstoreid HeaderMark B1 RegNo dateofbusiness NoRegEntries Tips OverRings Voids$ Voids# NetSales DP1_2Guests DP3Guests DP4Guests DetailMark fkdaypartid RecType GL B2 Sales
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 2 0 41005 NULL 2220.25
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 3 0 41005 NULL 9170.19
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 4 0 41005 NULL 670.75
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 2 0 42100 NULL 52.03
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 3 0 42100 NULL 398.34
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 4 0 42100 NULL 137.94
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 2 0 43000 NULL 78.92
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 3 0 43000 NULL 311.93
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 4 0 43000 NULL 163.74
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 2 0 44000 NULL 10.98
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 3 0 44000 NULL 44.23
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 4 0 44000 NULL 12
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 2 0 41950 NULL 247.33
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 3 0 41950 NULL 867.89
1061 H NULL 1 01/01/2008 NULL NULL NULL 113.26 35 12785.47 144 531 37 D 4 0 41950 NULL 38.54
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 2 0 41005 NULL 1998.09
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 3 0 41005 NULL 5950
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 4 0 41005 NULL 449.91
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 2 0 42100 NULL 65.58
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 3 0 42100 NULL 402.47
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 4 0 42100 NULL 94.51
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 2 0 43000 NULL 51.08
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 3 0 43000 NULL 376.61
1061 H NULL 1 01/02/2008 NULL NULL NULL 129.78 42 9168.35 143 361 23 D 4 0 43000 NULL 65.79
So, each date will have a header (denoted by "H"). With this table every record has an "H." This is not the way it needs to be. I need to compare dates and when they differ, create a new header and make the rest of the data (if any) a detail (denoted by "D").
I am toiling with the best way of doing this. So far, I am not having much luck. I have used arrays quite successfully in Java, but I am not sure that this is the best way to go here. I would have to get how many lines there are and read each line. Make the changes, and then go on to the next line. I think scanning the document line by line using a loop is the best way. However, I am not sure.
I am in need of some opinions. What do you think I should?
-
Apr 27th, 2009, 03:19 PM
#2
Re: Arrays and Strings
Create a datatable consisting of all the columns in that file then use either of these methods:
1. Use a TextFieldParser to read the file and fill in the datatable.
2. Use a streamreader and read each line, split it (by the tab character) into an array, then add a new datarow to your datatable with that data.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Apr 27th, 2009, 04:37 PM
#3
Re: Arrays and Strings
The datatable was what came first to my mind, as well, but I noted the bit about doing a comparison and changing things. An alternative would be to create a class that has a member for each of the fields in the table. You could then add a constructor to the class that took a string, split the string on Tab, then filled the fields appropriately. You could then have a List (of T) of this class type to hold all the items. The advantage to this approach appears to be just the organization, and you could do the same thing with a datatable, with the manipulation coming between splitting the string and adding the fields to the new datarow. To some extent it matters what you want to do with the data afterwards, which we don't know.
My usual boring signature: Nothing
 
-
Apr 27th, 2009, 04:38 PM
#4
Re: Arrays and Strings
As I understand your question...
You can have diffrent headers based on a date and details linked to a date.
sounds like you should need two objects:
a header object.
a detail object.
depending on your architecture you can opt to use two tables in a dataset to read the data in, with a relation between these(1 header table as parent and a details table as child)
Or an businessObject Header (a class) containing a list of details (another class) that has an attribute <serializable>
in both cases yoou can serialize them to an XML file.
a third party just needs the XML scheme to write code against. but an example file will do just as well.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Apr 27th, 2009, 06:27 PM
#5
Re: Arrays and Strings
What does the third party app want? I read your question as meaning that the third-party app wants data in a rigidly defined format that is already set in stone, while Dnereb read it as the third-party app has yet to be written. Both seem reasonable, but which one is right really affects the answer.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|