Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 29th, 2005, 07:59 AM
Authorized User
 
Join Date: Dec 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default In c# read a text file and delete a string

Hi
I am new to c#.

I have to do a program such that
the program sould read any text file.
such that in those txt files i have data as

for ex:

countryside.txt file has dat as follows

1|ANZ|7757 96745|
2|METWAY|33433|
3|WESTPAC|67357|
5|TOWN & COUNTRY|487457|
6|COMMONWEALTH|3427457|
7|BANK OF MELBOURNE|3576437|
8|NATIONAL AUST BANK|7547327|
10|S.B OF SA|74572745|
11|ST GEORGE BANK|3473574|

in all these dat are seprated by pipeline seperator.
no w what i have to do is , the program have to read the txt file and has to delete the last pipeline seperator . and save it as a new file.

the result should be as follows

1|ANZ|7757 96745
2|METWAY|33433
3|WESTPAC|67357
5|TOWN & COUNTRY|487457
6|COMMONWEALTH|3427457
7|BANK OF MELBOURNE|3576437
8|NATIONAL AUST BANK|7547327
10|S.B OF SA|74572745
11|ST GEORGE BANK|3473574

the pipeline of the last element in each row shouyld be removed
..

this should happen in whatever text file read


so please can anyone help me to do this program in c#.

D H O L



__________________
SureShot
 
Old June 30th, 2005, 05:00 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

string s ="";
            System.IO.StreamReader sr = new System.IO.StreamReader("c:\\my.txt");
            System.IO.StreamWriter sw = new System.IO.StreamWriter("c:\\my1.txt");
            while (true)
            {
                s=sr.ReadLine();
                if(s != null)
                {
                    s = s.Remove(s.LastIndexOf("|"),1);
                    sw.WriteLine(s);
                }
                else
                {
                    break;
                }
            }
            sr.Close();
            sw.Close();
            MessageBox.Show("Done");






Similar Threads
Thread Thread Starter Forum Replies Last Post
read text file senthilreddy ASP.NET 1.0 and 1.1 Basics 1 December 19th, 2010 10:56 PM
Read and Edit the text file stuartlittle C# 3 February 26th, 2008 05:35 AM
Read, write, delete and display xml file in php rapraj XML 0 December 27th, 2007 02:18 AM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
How to read a line from a text file ? nobitavn94 C# 3 November 25th, 2006 11:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.