Closed Thread
Results 1 to 2 of 2

Thread: C# Read two characters/numbers in a text file.

  1. #1
    Dodi300 is offline Newbie
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    C# Read two characters/numbers in a text file.

    Hello.
    Does anyone know how to read two characters/numbers in a text file?
    I've been using this:

    Code:
    using (StreamReader rdr = File.OpenText("C:/cname.txt"))
                {
                    int name = 0;
                    name = rdr.Peek();
                }
    That reads the first number in the file and stores it in 'name'.
    However now I need to read the first two numbers in a text file, and store it in the variable 'name'.

    Thanks for the help.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    lobo521 is offline Learning Programmer
    Join Date
    Jan 2010
    Posts
    57
    Rep Power
    8

    Re: C# Read two characters/numbers in a text file.

    The Peek method returns an integer value in order to determine whether the end of the file, or another error has occurred. This allows a user to first check if the returned value is -1 before casting it to a Char type.
    source StreamReader.Peek Method (System.IO)

    For reading contents of text file use ReadLine() method

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to read text file into array in C++?
    By bexita in forum C and C++
    Replies: 8
    Last Post: 10-28-2011, 08:44 AM
  2. [C#] how to read data from a text file
    By Crock in forum Classes and Code Snippets
    Replies: 0
    Last Post: 07-05-2011, 03:35 AM
  3. Read large text file efficiently?
    By FireGator in forum PHP Development
    Replies: 6
    Last Post: 09-06-2010, 08:56 PM
  4. Replies: 15
    Last Post: 07-27-2010, 01:27 PM
  5. Python Read From Text File
    By QuackWare in forum Classes and Code Snippets
    Replies: 0
    Last Post: 03-07-2010, 07:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

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