CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    7

    Question Stream read help

    I want to make I thing where this program takes a .txt and replaces letter with numbes. I know how to do this with a text box (.replace) but how to I do it to a txt file
    .NET4.0 / VS 2010

  2. #2
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: Stream read help

    Read your file with File.ReadAllText(string path) and then you can do FileWriteAllText(string path, string content)

  3. #3
    Join Date
    Jul 2012
    Location
    Ohio
    Posts
    13

    Re: Stream read help

    This would be better

    Code:
    using System;
    using System.IO;
    
    class Program
    {
        static void Main()
        {
    	//
    	// It will free resources on its own.
    	//
    	string line;
    	using (StreamReader reader = new StreamReader("file.txt"))
    	{
    	    line = reader.ReadLine();
    	}
    	Console.WriteLine(line);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured