streamreader

How do I separate each line of a .csv file into a string list>

跟風遠走 提交于 2020-01-05 01:10:33
问题 I am new to c# and am attempting to read in a .csv file and put each line of text in to a separate list item so I can sort it later. the .csv file is organised like so: 1;"final60";"United Kingdom";"2013-12-06 15:48:16"; 2;"donnyr8";"Netherlands";"2013-12-06 15:54:32"; etc This is my first attempt that doesn't work.It shows no errors in Visual studios 2010 but when I run the console program it displays the following Exception instead of the list. Exception of type 'System.OutOFMemoryException

How to close a stream properly?

自作多情 提交于 2020-01-04 10:59:08
问题 I have been assigned a task to write a program that will: Open a file. Read the content. Replace a specific word with another word. Save the changes to the file. I know for sure that my code can open, read and replace words. The problem occurs when i add the "Save the changes to the file" - part. Here is the code: open System.IO //Getting the filename, needle and replace-word. System.Console.WriteLine "What is the name of the file?" let filename = string (System.Console.ReadLine ()) System

Why does my StreamReader.ReadLine () in F# not read \n as a new line?

丶灬走出姿态 提交于 2020-01-04 05:26:37
问题 I am currently trying to read a file as this: 53**7****\n6**195***\n*98****6*\n8***6***3\n4**8*3**1\n7***2***6\n*6****28*\n***419**5\n****8**79\n And write it into the screen, but with new lines instead of the /n. On the msdn description of the method StreamReader.ReadLine () it says that: A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does

Loading a .csv file into dictionary, I keep getting the error “cannot convert from 'string[]' to 'string'”

我的未来我决定 提交于 2020-01-01 04:54:30
问题 I've used streamreader to read in a .csv file, then i need to split the values and put them into a dictionary. so far i have: namespace WindowsFormsApplication2 { public partial class Form1 : Form { Dictionary<string, string> dict = new Dictionary<string, string>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader("textwords0.csv")) { string line; while ((line = reader.ReadLine()) != null) { string[]

Performing a subtotal on filtered data from a streamreader

半世苍凉 提交于 2019-12-31 07:00:15
问题 edit as question is unanswered I have a filtered output based on 1 criteria (first 3 numbers are 110,210 or 310,to give 3 distinct groups) to console from streamreader. Question edited because first answer was a literal solution to the specific example I gave, the real strings I'm using are 450 ASCII characters long. I have adjusted the example strings to remedy this, anything that works on the sample data will work on what I have. so what i really need is something that can, depending on the

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

霸气de小男生 提交于 2019-12-31 05:55:52
问题 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

How to convert Streamreader data to XmlDocument?

我与影子孤独终老i 提交于 2019-12-31 02:23:28
问题 In C#, I am trying to get call a webservice which returns an XML file. I can make a HttpWebRequest to the webservice and store the output in a StreamReader. But how can I convert this data into an XMLDocument? 回答1: Use XmlDocument.Load() - I'm using the overload that accepts an XmlReader to cash in on XmlReader.Create's auto-encoding detection: XmlDocument document = new XmlDocument(); using(Stream stream = request.GetResponse().GetResponseStream()) { using(XmlReader reader = XmlReader.Create

VB.NET - Reading a text file containing tab-separated integers/doubles and storing them in arrays

橙三吉。 提交于 2019-12-31 01:56:08
问题 I have a text file containing tab-seperated integers and doubles, e.g.: 5[TAB]0.3[TAB]2.9[TAB]61[TAB]110 8[TAB]1.1[TAB]5.2[TAB]13[TAB]45 1[TAB]0.8[TAB]1.4[TAB]28[TAB]33 ... What I need is a convenient way to access each line as a double array in VB.NET - so that the first array would be [ 5.0 0.3 2.9 61.0 110.0 ], the second array would be [ 8.0 1.1 5.2 13.0 45.0 ], and so on... How can this be accomplished using the StreamReader? 回答1: If it's ok to use a list of lists instead of a list of

Zip file is getting corrupted after downloading from server in C#

空扰寡人 提交于 2019-12-30 14:15:34
问题 request = MakeConnection(uri, WebRequestMethods.Ftp.DownloadFile, username, password); response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); //This part of the code is used to write the read content from the server using (StreamReader responseReader = new StreamReader(responseStream)) { using (var destinationStream = new FileStream(toFilenameToWrite, FileMode.Create)) { byte[] fileContents = Encoding.UTF8.GetBytes(responseReader.ReadToEnd());

How to open a StreamReader in ShareDenyWrite mode?

£可爱£侵袭症+ 提交于 2019-12-30 09:29:49
问题 How do i open a StreamReader with FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE? Same question, slightly expanded How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can read the file? How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can modify the file while i'm reading it? How do i open a StreamReader so that i can read an encoded text file, with sharing