473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Difficult Question: Read/Modify file

Thanks in advance for reading this.

Let's say I have a file (file01) with this data in ASCII (ignore line col):

line01 123abc
line02 Header01 Starts blah var
line03 detail01 000001
line04 detail02 000002
line05 detail03 000003
line06 detail04 000004
line07 detail05 000005
line08 detail06 000006
line09 detail07 000007
line10 Header01 Ends
line11 Header02 Starts blah var
line12 detail01 000001
line13 detail02 000002
line14 detail03 000003
line15 detail04 000004
line16 detail05 000005
line19 Header03 Ends

Here's what I need to do:

1. traverse each line and modify some section of the line
(it could postion 10-20) according to some logic in a function.

2. For Header line, I need to know the last detail line for that header
of a section (it could postion 20-25). So for Header02 (line11) I would
need to grab the value '000005' (line16).

The result for file01 will have it's line modified accordingly.

The main question is how can I traverse down line by line, and
when I get to the Header, somehow get the value of the last detail line
for that header, and continue the next line after the header which
is the first detail line.

I know you can do this in C by creating a dummy pointer to point
to the header and then traverse to the last detail line and return the
value. And then destroy the pointer.

I just don't know how to do this is .NET.

Thanks in advance for your replies!

Jan 12 '07 #1
2 1391

"ank2go" <an****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
Thanks in advance for reading this.

Let's say I have a file (file01) with this data in ASCII (ignore line
col):

line01 123abc
line02 Header01 Starts blah var
line03 detail01 000001
line04 detail02 000002
line05 detail03 000003
line06 detail04 000004
line07 detail05 000005
line08 detail06 000006
line09 detail07 000007
line10 Header01 Ends
line11 Header02 Starts blah var
line12 detail01 000001
line13 detail02 000002
line14 detail03 000003
line15 detail04 000004
line16 detail05 000005
line19 Header03 Ends

Here's what I need to do:

1. traverse each line and modify some section of the line
(it could postion 10-20) according to some logic in a function.

2. For Header line, I need to know the last detail line for that header
of a section (it could postion 20-25). So for Header02 (line11) I would
need to grab the value '000005' (line16).

The result for file01 will have it's line modified accordingly.

The main question is how can I traverse down line by line, and
when I get to the Header, somehow get the value of the last detail line
for that header, and continue the next line after the header which
is the first detail line.

I know you can do this in C by creating a dummy pointer to point
to the header and then traverse to the last detail line and return the
value. And then destroy the pointer.

I just don't know how to do this is .NET.

Thanks in advance for your replies!
Have a look at the FileStream class and its members:

http://msdn2.microsoft.com/en-us/lib...ilestream.aspx

http://msdn2.microsoft.com/en-us/lib...m_members.aspx
Jan 13 '07 #2
I assume that you have no control over the file structure? There are easier
ways if you do.

First I wouldn't attempt to position, read & write these things with the
filestream. I think you'll be at it for a long time and (unless it has
gotten especially clever lately) you aren't going to be able to insert
things, i.e. lengthen or shorten any of the "entries". You'd also have a
lot of lookahead, skip back sort of action going on making it prone to
error.

What you are describing is the data portion of a class. See if you can
describe a class with properties representing whatever is on line01 and a
collection of headers and a collection of details within headers. Then
create a Load() method (using a filestream but notice you're only walking
the file from beginning to end) that reads a line, decides what it is and
adds it to an object of that class you designed.

Now you have it all in an object and clearly you can add other methods which
will locate a specific line, edit that line, etc. When you're all done you
call your Save() method which writes back a new text file.

Does that work for you?

Tom

"ank2go" <an****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
Thanks in advance for reading this.

Let's say I have a file (file01) with this data in ASCII (ignore line
col):

line01 123abc
line02 Header01 Starts blah var
line03 detail01 000001
line04 detail02 000002
line05 detail03 000003
line06 detail04 000004
line07 detail05 000005
line08 detail06 000006
line09 detail07 000007
line10 Header01 Ends
line11 Header02 Starts blah var
line12 detail01 000001
line13 detail02 000002
line14 detail03 000003
line15 detail04 000004
line16 detail05 000005
line19 Header03 Ends

Here's what I need to do:

1. traverse each line and modify some section of the line
(it could postion 10-20) according to some logic in a function.

2. For Header line, I need to know the last detail line for that header
of a section (it could postion 20-25). So for Header02 (line11) I would
need to grab the value '000005' (line16).

The result for file01 will have it's line modified accordingly.

The main question is how can I traverse down line by line, and
when I get to the Header, somehow get the value of the last detail line
for that header, and continue the next line after the header which
is the first detail line.

I know you can do this in C by creating a dummy pointer to point
to the header and then traverse to the last detail line and return the
value. And then destroy the pointer.

I just don't know how to do this is .NET.

Thanks in advance for your replies!

Jan 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gardner Pomper | last post by:
Hi, I am pretty new to python, so be gentle :) I have a python script that spawns a number of threads (configurable) on a 12 processor AIX RISC-6000 machine. It works fine, so long as I am...
13
by: Hadi | last post by:
Hi, I have two files and the array that contains 20 words in it. I'm trying to write python script that suppose achieve the following: -Open file-1, read the line that contains 20 words separated...
55
by: ben | last post by:
is it true that a function without an inline keyword never get inlined? If not true when is it inlined or not? ben
6
by: Jimmy Clay | last post by:
I have a very basic question about how to include files to be used by another file. I'm trying to include a bad word filter into the guestmap on my website. I know almost nothing about PHP code....
34
by: Mathieu Trentesaux | last post by:
Hello I downloaded Office 2007 for this reason : It seems, once again, that it is impossible to save any modification done in a VBA library, from the main project in Access. The save button...
2
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this,...
5
by: polas | last post by:
Good morning, I have a quick question to clear up some confusion in my mind. I understand that using a string literal in a declaration such as char *p = "string literal" declares a pointer to...
1
by: pitjpz | last post by:
We have moved our Database to another server. The server it was on used SQL 4 and the new one its on now uses SQL5 the only problem we can find is that when you attempt to delete a record from...
6
by: Ramesh | last post by:
Hello, I am using the ofstream class to create a text file with keys and values like: Key1=Value10 Key2=Value15 Key3=Value20 In case I need to set a new value for Key2, say value50 - I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.