streamreader

Using StreamReader to count duplicates?

和自甴很熟 提交于 2019-12-08 10:26:47
问题 I'm using streamreader now to read a file of people names, it is a text file, of people first names, so there are obviously duplicates, and i want to be able to display how many people have the same now so for example: josh alex josh john alex I want it to say, josh 2 alex 2 john 1 but I can't seem to find an easy way of doing this, what would be the easiest way about doing this, 回答1: I'd say use a Dictionary<string, int> . Dictionary<string, int> firstNames = new Dictionary<string, int>();

A way out from getting SystemOutOfMemoryException while importing from large text file into database

老子叫甜甜 提交于 2019-12-08 08:37:13
问题 we're using ZyWall to guard our servers from external intrusions. It generates daily log files with huge sizes, over a GB, sometimes 2 GBs. They ususally contain more than 10 millions of lines. Now my task is to write an application that will import these lines into Oracle database. I'm writing it in C#. What I'm currently doing is: I read the logfiles line by line. I do not load the whole file at once: using(StreamReader reader=new StreamReader("C:\ZyWall.log")) { while ((line=reader

StreamReader ReadLine returns null when not EOF

谁说胖子不能爱 提交于 2019-12-08 06:26:26
Having a strange problem that I've never encountered nor heard of happening. It seems that occasionally, the ReadLine() function of the StreamReader class will return NULL, as if it's at the end of the file, BUT it's not. My log file indicates that everything is happening just as if it had actually reached the end of the file, but yet it's only processing part of it. There doesn't appear to be any consistency, because if I restart the process from scratch, the whole file is processed without incident. Clearly, there is nothing funky in the file itself, or it would do this on the same line each

My UWP app won't read a txt file [duplicate]

浪尽此生 提交于 2019-12-08 06:02:30
问题 This question already has answers here : Windows 10 Universal App File/Directory Access (6 answers) Closed 2 years ago . I was wondering if anyone would know how to get an Universal Windows app to read a txt file. StreamReader lezer = new StreamReader(@"C:\Users\LotteDiesveld\Documents\Visual Studio 2015\Projects\Jaar 1\Periode 2\OIS 12\Eindopdracht\Personen.txt"); tbPersonen.Items.Add(lezer.ReadToEnd()); I've also tried this StorageFile file = await StorageFile.GetFileFromApplicationUriAsync

StreamReader ReadLine returns null when not EOF

…衆ロ難τιáo~ 提交于 2019-12-08 05:38:05
问题 Having a strange problem that I've never encountered nor heard of happening. It seems that occasionally, the ReadLine() function of the StreamReader class will return NULL, as if it's at the end of the file, BUT it's not. My log file indicates that everything is happening just as if it had actually reached the end of the file, but yet it's only processing part of it. There doesn't appear to be any consistency, because if I restart the process from scratch, the whole file is processed without

C# Reading stream from TcpClient

不问归期 提交于 2019-12-08 05:35:46
问题 I'm making a server - client program using TcpClient and server. To send from the server I use: static void send(string data) { sw.WriteLine(data + Environment.NewLine); } And when the client connects I'm sending some text: client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code And to read from client: string data; data = sr.ReadLine(); if(data != string.Empty || data !=

C# Stream Reader adding \n to XML

那年仲夏 提交于 2019-12-08 05:18:52
问题 I use the StreamReader class to obtain XML for my GeoCoding process from Google. StreamReader srGeoCode = new StreamReader(WebRequest.Create(Url).GetResponse().GetResponseStream()); String GeoCodeXml = srGeoCode.ReadToEnd(); XmlDocument XmlDoc = new XmlDocument(); GeoCode oGeoCode = new GeoCode(); XmlDoc.Load(GeoCodeXml); I get XML back but it adds \n and other extras to the XML <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<kml xmlns=\"http://earth.google.com/kml/2.0\"><Response>\n <name> I

C# get text from file between two hashes

心已入冬 提交于 2019-12-08 04:51:01
问题 In my C# program (at this point) I have two fields in my form. One is a word list using a listbox; the other is a textbox. I have been able to successfully load a large word list into the listbox from a text file. I can also display the selected item in the listbox into the textbox this way: private void wordList_SelectedIndexChanged(object sender, EventArgs e) { string word = wordList.Text; concordanceDisplay.Text = word; } I have another local file I need to get at to display some of its

vb.net Reading from a .txt file and displaying the contents

笑着哭i 提交于 2019-12-08 04:00:23
问题 I'm making a simple program which reads and writes .txt files. I've got the program to write to and save a .txt file however I'm having some trouble reading from .txt files. Here's what I've got so far: Using openTxt As New OpenFileDialog() If openTxt.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim displayForm As New Form Dim textReader As New System.IO.StreamReader(openTxt.FileName) displayForm.ListBox1.Text = textReader.ReadToEnd textReader.Close() displayForm.Show() Else MessageBox

C# get text from file between two hashes

孤街浪徒 提交于 2019-12-08 03:55:32
In my C# program (at this point) I have two fields in my form. One is a word list using a listbox; the other is a textbox. I have been able to successfully load a large word list into the listbox from a text file. I can also display the selected item in the listbox into the textbox this way: private void wordList_SelectedIndexChanged(object sender, EventArgs e) { string word = wordList.Text; concordanceDisplay.Text = word; } I have another local file I need to get at to display some of its contents in the textbox. In this file each headword (as in a dictionary) is preceded by a #. So, I would