streamreader

Read each line in file and put each line into a string

…衆ロ難τιáo~ 提交于 2019-12-02 08:40:40
I have a text file that I want to read in and put each line from the file into its own string. So the file will have 4 lines: 2017-01-20 05:59:30 +353879833382 971575 Michael So in the code I need to read in the file and split up each line and put them into a string i.e the first line will equal to string date, second line will equal to string time etc Code: public static void ParseTXTFile(string FileName, int CompanyID) { try { FileInfo file = new FileInfo(FileName); string Date; string Time; string Phone; string JobNo; string Name; using (CsvReader reader = new CsvReader(new StreamReader

Stream Reader Readline detect newline characters

一世执手 提交于 2019-12-02 08:12:47
I'm trying to remove any "new line" characters from each line of text in my log file. Below is an example entry that I am reading in with a Stream Reader :- <![LOG[Raising event: [SMS_CodePage(850), SMS_LocaleID(2057)] instance of SoftDistProgramStartedEvent { AdvertisementId = "000216F6"; ClientID = "GUID:B55C2757-CBAE-468E-B54F-46CAF2ECF68F"; CommandLine = "\"C:\\WINNT\\system32\\cscript.exe\" /nologo Shutdown_Desktops_Overnight.vbs"; DateTime = "20130211080211.784000+000"; MachineName = "DWD*****"; PackageName = "0000073C"; ProcessID = 2516; ProgramName = "Shutdown Desktops Overnight";

C# StreamReader input files from labels?

醉酒当歌 提交于 2019-12-02 03:47:38
问题 I have been using a StreamReader inputFile code from a ListBox and it works great, However, I would like to input the data from the .txt file into a Label box instead, is this possible? This is the code I tried and it gives me an error description stating Use of unassigned local variable 'total' private void Form1_Load(object sender, EventArgs e) { try { int total = 0; int highScore; StreamReader inputFile; inputFile = File.OpenText("HighScore.txt"); while (!inputFile.EndOfStream) { highScore

C# StreamReader input files from labels?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 03:07:14
I have been using a StreamReader inputFile code from a ListBox and it works great, However, I would like to input the data from the .txt file into a Label box instead, is this possible? This is the code I tried and it gives me an error description stating Use of unassigned local variable 'total' private void Form1_Load(object sender, EventArgs e) { try { int total = 0; int highScore; StreamReader inputFile; inputFile = File.OpenText("HighScore.txt"); while (!inputFile.EndOfStream) { highScore = int.Parse(inputFile.ReadLine()); total += highScore; } inputFile.Close(); highscoreLabel.Text =

Program Issues Going From Unity To HoloLens - Cannot convert from 'string' to 'System.IO.Stream'

寵の児 提交于 2019-12-02 01:47:49
I have a program written in Unity using C# that initializes a new StreamReader and proceeds to read the text data from a text file I have stored in Unity's resources folder. Everything works fine when I click play in Unity -everything works and the text is read and displayed perfectly. However, when I try to build it in order to run it via the HoloLens emulator (Platform: Windows Store, SDK: Universal 10, Build and Run On: Local Machine), I get the error: error CS1503: Argument 1: cannot convert from 'string' to 'System.IO.Stream'. I don't understand why this error is even showing up in the

StreamReader Read method doesn't read number of chars specified

青春壹個敷衍的年華 提交于 2019-12-01 23:22:07
问题 I have to parse a large file so instead of doing: string unparsedFile = myStreamReader.ReadToEnd(); // takes 4 seconds parse(unparsedFile); // takes another 4 seconds I want to take advantage of the first 4 seconds and try to do both things at the same time by doing something like: while (true) { char[] buffer = new char[1024]; var charsRead = sr.Read(buffer, 0, buffer.Length); if (charsRead < 1) break; if (charsRead != 1024) { Console.Write("Here"); // debuger stops here several times why? }

StreamReader.ReadLine not working over TCP when using \r as line terminator

别来无恙 提交于 2019-12-01 22:17:24
问题 When I use only \r as a line terminator, the StreamReader.ReadLine() method doesn't work. It works if I use Environment.NewLine , \r\n or \ra ("a" being any character). Is this a bug? The same problem doesn't occurs when using MemoryStream instead of NetworkStream. What workarounds can I use if I can't change the protocol? My service Thread service = new Thread((ThreadStart)delegate { TcpListener listener = new TcpListener(IPAddress.Loopback, 2051); listener.Start(); using (TcpClient client =

Moving the file cursor up lines?

左心房为你撑大大i 提交于 2019-12-01 21:31:14
I've googled this like crazy, and I can't seem to find any reference at all to this particular type of problem. I have a StreamReader object with a file, and I want to read over a certain number of lines in the file a certain number of times, however, There doesn't seem to be any way to move the file cursor to certain positions in the file. (No code because I have no clue how I would go about writing something like this) You should be able to use myStreamReader.BaseStream.Position = desiredPosition; myStreamReader.DiscardBufferedData(); to move the stream to a specific place. EDIT: The next

StreamReader.ReadLine not working over TCP when using \\r as line terminator

こ雲淡風輕ζ 提交于 2019-12-01 20:44:59
When I use only \r as a line terminator, the StreamReader.ReadLine() method doesn't work. It works if I use Environment.NewLine , \r\n or \ra ("a" being any character). Is this a bug? The same problem doesn't occurs when using MemoryStream instead of NetworkStream. What workarounds can I use if I can't change the protocol? My service Thread service = new Thread((ThreadStart)delegate { TcpListener listener = new TcpListener(IPAddress.Loopback, 2051); listener.Start(); using (TcpClient client = listener.AcceptTcpClient()) using (NetworkStream stream = client.GetStream()) using (StreamReader

StreamReader Read method doesn't read number of chars specified

放肆的年华 提交于 2019-12-01 20:24:15
I have to parse a large file so instead of doing: string unparsedFile = myStreamReader.ReadToEnd(); // takes 4 seconds parse(unparsedFile); // takes another 4 seconds I want to take advantage of the first 4 seconds and try to do both things at the same time by doing something like: while (true) { char[] buffer = new char[1024]; var charsRead = sr.Read(buffer, 0, buffer.Length); if (charsRead < 1) break; if (charsRead != 1024) { Console.Write("Here"); // debuger stops here several times why? } addChunkToQueue(buffer); } here is the image of the debuger: (I added int counter to show on what