1
Answer

StreamReader.Read() method

wixz64

wixz64

19y
8.8k
1
Ive noticed something realy odd when i was working with this method i was reading from a file and read char by char.. StreamReader fileRoomsReader = new StreamReader("file.txt"); Filedata[] loadedData = new Filedata[2]; string buffer =""; char ch; string [] buffer2 = new string[5]; int line = 0,tab = 0; while(line <2) { while(tab <5) { ch = (char)fileRoomsReader.Read(); if(ch == ',') { buffer2[tab] = buffer; buffer = ""; tab++; } else if(ch == '\r' || ch == '\n') { buffer2[tab] = buffer; buffer = ""; /* >>>>>>>>>*/ ch = (char)fileRoomsReader.Read(); //The wierd part... tab = 5; } else { buffer += ch; } } //Create an object with loaded data.. loadedData[line] = new Filedata(buffer2[0],Int32.Parse(buffer2[1]),buffer2[2],Int32.Parse(buffer2[3])); tab = 0; line += 1; } if i didnt add that line that is marked i noticed it stopped reading data for some reason.. now its fixed so its not a problem but if anyone just chould explain why this happens.. ?? because for me it seems like its reading 2 * ch to end a line..
Answers (1)