Solved

Using C# open text file and add text to the beginning and end  of each line

Posted on 2008-06-25
3
3,722 Views
Last Modified: 2010-04-21
Hi,

I want to open a text file then add an open quotation mark to the beginning of each line and a quotation mark and a plus sign to the end of each line.

I am trying to do this in C# but cannot find any good examples.

Thanks for any help,
Bonnie
0
Comment
Question by:Bonnie_K
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:Sh4d1
ID: 21865030
I suggest to read file in for/while read all lines into array and then with regular expressions add at the start and end of line what you want, then write changes back to file.
0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 21865077
There are plently of ways to do this, here is one of them:

        String inputFile = Server.MapPath("./Test.txt");
        StreamReader sr = new StreamReader(inputFile);
        String filecontents = sr.ReadToEnd();
        sr.Close();

        StringReader gr = new StringReader(filecontents);
        StreamWriter gw = new StreamWriter(inputFile, false);

        while (gr.Peek() != -1)
        {
            gw.WriteLine("\"" + gr.ReadLine() + "\"+");
        }

        gr.Close();
        gw.Close();
0
 

Author Closing Comment

by:Bonnie_K
ID: 31470534
Thank you very much, works perfectly!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question