Hello.
Does anyone know how to read two characters/numbers in a text file?
I've been using this:
That reads the first number in the file and stores it in 'name'.Code:using (StreamReader rdr = File.OpenText("C:/cname.txt")) { int name = 0; name = rdr.Peek(); }
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.![]()
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks