Z.K. wrote:
Never mind, I figured it out.
Actually, I still had a problem, but now I have figured it out. Actually
it is simpler than I expected.
char charInput;
int input = 0;
while(freader.Peek() > -1)
{
input = freader.Read();
//charInput = (char)input;
arList.Add((char)Input);
}
freader.Close();
Z.K.
Z.K.,
You know that your code is detecting the end of the file, not the end of
a line in the file, right? I thought your original question was
detecting the end of lines. If that's the case, then StreamReader has a
ReadLine() method which will help.
Also, processing one character at a time and adding to an ArrayList of
characters will not be very efficient regarding performance (unless the
input is small).
You may want to try something like:
StreamReader reader = new StreamReader(an_input_stream);
int buffer_size = 256;
char[] char_buffer = new char[buffer_size];
StringBuilder result = new StringBuilder();
using (reader)
{
int count = reader.Read(char_buffer, 0, buffer_size);
while (count > 0)
{
result.Append(char_buffer, 0, count);
count = reader.Read(char_buffer, 0, buffer_size);
}
}
return result.ToString();
(Note: I didn't compile this, so the code might not compile directly.)
Hope this helps.
Dan Manges