473,387 Members | 1,859 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,387 software developers and data experts.

Edit text file.

I need to be able to open a file, search for a line of text and change the
line. I am able to use the streamreader to find the line, but can seem to
find a way to alter the line.
Dec 5 '05 #1
4 1260
Shawn wrote:
I need to be able to open a file, search for a line of text and change the
line. I am able to use the streamreader to find the line, but can seem to
find a way to alter the line.


AFAIK, You will need to open a streamwriter and write out the entire
file with your altered text.

Chris
Dec 5 '05 #2
Ahh, I never thought of that. Ok, I will try.

Thanks!!!

"I Don't Like Spam" <no@spam.com> wrote in message
news:Of****************@TK2MSFTNGP11.phx.gbl...
Shawn wrote:
I need to be able to open a file, search for a line of text and change
the line. I am able to use the streamreader to find the line, but can
seem to find a way to alter the line.


AFAIK, You will need to open a streamwriter and write out the entire file
with your altered text.

Chris

Dec 5 '05 #3
steps to take

read the file in memory
alter the line
write the file back to disk ( overwite the original file for instance )

regards

Michel Posseth [MCP]

"Shawn" <sh**********@ccci.org> wrote in message
news:eC****************@TK2MSFTNGP12.phx.gbl...
I need to be able to open a file, search for a line of text and change the
line. I am able to use the streamreader to find the line, but can seem to
find a way to alter the line.

Dec 5 '05 #4
Michael,
read the file in memory
alter the line
write the file back to disk ( overwite the original file for instance )

I find that a dangerous operation, I advice forever first to rename the old
one (better put it in the temp), and after the succesful write delete that

:-)

Cor
Dec 5 '05 #5

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

Similar topics

6
by: matt | last post by:
I am using a text file as a database, each field delimited by || I want to be able to print all lines to a page, then by selecting one (with, say, a radio button) it will load into the form at the...
4
by: Option^Explicit | last post by:
What I'm trying to do: Open a text file and display the contents in a text box (I've done this) Need to be able to edit the file from within the textbox and have it save back to the source...
4
by: Abhishek | last post by:
Hi! I need to edit a text file. I need to replace a given text in the file with a new one. This text can exist anywhere in the file, so i first need to locate the text position and then edit...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
0
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
2
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
1
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
1
by: Xicon | last post by:
I am looking to create a program that is able to edit a text file that is not located within the program. This particular text file is always in the exact same location and is always named the exact...
0
by: yemen2007 | last post by:
hi i have some problem in my project i want help . the problem it is update or edit to the file in xml.my project is write and update/edit to xml file. i done the first one is write bout i have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.