|
-
Nov 2nd, 2005, 08:07 AM
#1
Thread Starter
Lively Member
Read from text file and write to text file
I'm not sure how to go about doing this. I know how to read from a textfile and write to a text delimited file, but I need to be able to extract specific data from the text file that I'm reading and not sure how to go about doing that. Here's an example of the file that I'm reading from and then an example of what data it is extracting and write to 3 text delimated files.
Text file to read from:
VB Code:
CDL8GL02122 PR045050000012345 CHECKS 03
CDL8GL02322 PR045050000234334 DED B 03
CDL8GL09323 PR045050008821677 LTD 03
CDL8GL50203-30 PR045050003239083 REGULAR EARNINGS 03
CDL8GL50203-44 PR045050000022234 DED 29 03
CDL8GL51232-51 PR045050000776757 DED 29 03
CDL8GL52332-32 PR045050002343234 VOLUNTARY LIFE 03
CDL8GL52332-31 PR045050003587821 REGULAR EARNINGS 03
CDL8GL52332-33 PR045050002324879 REGULAR EARNINGS 03
CDL8GL52332-34 PR045050022387767 REGULAR EARNINGS 03
CDL8GL60923-23 PR045050000589876 VOLUNTARY LIFE 03
CDL8GL70934-22 PR045050000334452 VOLUNTARY LIFE 03
CDL8GL70983-25 PR045050000234323 DED 29 03
After reading it from the source textfile, it will write it into 3 different files depending what is from the source textfile.
VB Code:
File#1
2122 ADP 0450 0 123.45
2322 ADP 0450 0 2343.34
9323 ADP 0450 0 88216.77
70983-25 ADP 0450 2343.23 0
70934-22 ADP 0450 3344.52 0
FILE#2
50203-30 ADP 0450 32390.83 0
50203-44 ADP 0450 222.34 0
51232-51 ADP 0450 7767.57 0
52322-32 ADP 0450 23432.34 0
52322-31 ADP 0450 0 35878.21
FILE#3
63223-33 ADP 0450 23248.79 0
62332-34 ADP 0450 223877.67 0
60923-23 ADP 0450 0 5898.76
What I need help with is how would I trim each line so that it would pull specific data from the source file per line and then write it to a text delimited file depending on what is the account number? The account number from the above example are the ones beginning with "CDL" and will always stay like that.
I was thinking about reading it to an array and then trim each strings, but I'm not really sure. I need to be able to put these into each cell within a row from the text delimited file. Can someone with experience help guide me on what's the best approach? Let me know if you need more details.
Thanks,
Chris
-
Nov 2nd, 2005, 09:26 AM
#2
Re: Read from text file and write to text file
How about ADO.NET? You can use ADO.NET to read text files. You can get the connectionstring for it form www.connectionstrings.com
-
Nov 2nd, 2005, 09:49 AM
#3
Thread Starter
Lively Member
Re: Read from text file and write to text file
Thanks for the help. If I was to use ADO.NET to read the textfile, can I use substring to pull what I need from each line it reads?
I need to take one line and pull separate data from there and then put it into a delimited text file. So for example the data below will be in 4 cells:
-
Nov 2nd, 2005, 06:42 PM
#4
Re: Read from text file and write to text file
Well what code do you have right now?? Are you pulling the data you need already? Is the prob just in the writing of the files?? Also, where is the money being pulled from?
-
Nov 2nd, 2005, 07:20 PM
#5
Re: Read from text file and write to text file
Is your original file delimited by tabs, or are those spaces? If it's delimited by tabs, you can use those to separate it via ADO.NET. If they are just lined up by spaces, you can use the substring function to select the fields.
Bill
-
Nov 3rd, 2005, 07:23 AM
#6
Thread Starter
Lively Member
Re: Read from text file and write to text file
The problem I'm having is how would I write to another file and be able to extract specific data from each line item. As you can see one line has four parts to it. Depending on the account number, the money could be either credit or debit.
As for where I"m getting the money here's is where it's being pulled from.
VB Code:
CDL8GL02122 PR0450500000[B]12345[/B] CHECKS 03
It will automatically insert a decimal right before the last 2 digits. So the money will look like 123.45.
From my understanding this would be very easy if I'm pulling the data from a database and use a case statement for my filter with a substring to extract specific part of the data, then put it into a csv file, but with reading from another file I'm not sure.
Let me try coding using substrings and if I get stuck I will post again.
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
|