streamreader

Writing List<String> contents to text file after deleting string

妖精的绣舞 提交于 2019-12-26 07:19:35
问题 I'm trying to get the contents of a Text File, delete a line of string, and re-write back to the Text File, deleting the line of string. I'm using StreamReader to get the text, importing into a List, removing the string, then rewriting using StreamWriter. My problems arises somewhere around the removing or writing of the string. Instead of writing back the existing, non deleted contents to the text file, all the text is replaced with : System.Collections.Generic.List`1[System.String] My code

Writing List<String> contents to text file after deleting string

时光毁灭记忆、已成空白 提交于 2019-12-26 07:19:11
问题 I'm trying to get the contents of a Text File, delete a line of string, and re-write back to the Text File, deleting the line of string. I'm using StreamReader to get the text, importing into a List, removing the string, then rewriting using StreamWriter. My problems arises somewhere around the removing or writing of the string. Instead of writing back the existing, non deleted contents to the text file, all the text is replaced with : System.Collections.Generic.List`1[System.String] My code

Replacing a certain word in a text file

纵饮孤独 提交于 2019-12-25 18:49:06
问题 I know this has been asked a few times, but I have seen a lot of regex etc., and I'm sure there is another way to do this with just a stream reader/writer. Below is my code. I'm trying to replace "tea" with the word "cabbage". Can somebody help? I believe I have the wrong syntax. namespace Week_9_Exer_4 { class TextImportEdit { public void EditorialControl() { string fileName; string lineReadFromFile; Console.WriteLine(""); // Ask for the name of the file to be read Console.Write("Which file

Performance issue with SqlBulkCopy and DataTable

两盒软妹~` 提交于 2019-12-25 16:51:04
问题 I need to efficiently import large amount of data from file to database. I have few rrf file which contain that data, the size of a file could be > 400mb and eventually it could be > 2 million record to database from file. What did I do: I am reading needed records in DataTable. using (StreamReader streamReader = new StreamReader(filePath)) { IEnumerable<string> values = new List<string>(); while (!streamReader.EndOfStream) { string line = streamReader.ReadLine().Split('|'); int index = 0;

How to copy specific lines from one file to another?

[亡魂溺海] 提交于 2019-12-25 08:07:12
问题 I have a text file with about 3000 lines. Some lines start with numbers and some with text. For example: Lines that start with numbers: 001 some text 0017 some text 8 some text... Lines that start with text: some text, some text... I want to copy lines that start with numbers to result.text. Lines that start with text to log.txt. Thanks a lot. 回答1: It can be done in one statement for one file WriteAllLines("new file",  ReadLines("source file") .Where(line => line.Lenth > 0 && Char.IsDigit

Alternative to ReadLine?

被刻印的时光 ゝ 提交于 2019-12-25 07:57:02
问题 I'm trying to read some files with ReadLine , but my file have some break lines that I need to catch (not all of them), and I don't know how to get them in the same array, neither in any other array with these separators... because... ReadLine reads lines, and break these lines, huh? I can't replace these because I need to check it after the process, so I need to get the breaklines AND the content after that. That's the problem. How can I do that? Here's my code: public class ReadFile {

Find strings in one file in another and output certain columns

这一生的挚爱 提交于 2019-12-25 07:22:30
问题 I have a file that contains CampaignNames and IDs. The two fields are separated by a pipe | . The IDs are separated by a space. I want to find all rows in a file (thorpe þ delimited) that contain the IDs, and output those rows into separate files per name. This file is usually 4-7 GB, sometimes larger. campaigns.txt : Name|NameID FirstName|123 212 445 39 SecondName|313 939 ThirdName|219 Data ID File: DateþIDþCode 10-22-14þ123þAbc 10-24-16þ212þPow 09-18-15þ219 So I would want 3 files created.

Best way to save low amount of configuration

喜欢而已 提交于 2019-12-25 05:32:20
问题 I have to save the configuration of my device, and a friend told me that as it is just 2(two) fields, it would be better save/read it on a .txt file instead create a table. Is that true ? Will it be quite faster? Or doesn't matter ? If so, how may I do that? I know how to Write/Read on text file using System.IO and StreamReader/StreeamWriter . I just wanted to know if it is true that it would be faster and an idea of how could I read it and set the value read to the configuration.... Maybe

Mixing StreamReader.Read… and Stream.Read

十年热恋 提交于 2019-12-25 02:48:14
问题 I have a TCP socket that I use for RTSP communication. As the data is a mixture of line based textual data and byte sized blocks, I attached a StreamReader to the tcpClient.GetStream() , and call .ReadLine() whenever needed for the textual data. When I need to read a response body, I have a fixed byte count so I tried using stream.Read() but that blocks, presumably as the StreamReader has already read the data into its own buffer. As that does character encoding, it only reads a fixed number

Manipulate and Dedupe Array of data for display into DataGrid

早过忘川 提交于 2019-12-25 02:43:35
问题 I have an array of data brought into my VB .Net program that follows the following format. Order No.|Description|Colour|Size|Total Qty.|Order Date|Expected D.D. 2273448|NOK OPAQUE KNEE HIGH |BLACK |X |001 |02/12/2013 |05/12/2013 2231428|UX XR WARM HOLD UPS |NAVY |ONE SIZE |001 |02/12/2013 |05/12/2013 2231428|NHS SOFTHOLD HOLD-UP |BLACK |X |001 |02/12/2013 |05/12/2013 2265640|KX XR WARM TIGHTS |BLACK |XXL |001 |02/12/2013 |05/12/2013 2273448|NOK OPAQUE KNEE HIGH |BLACK |X |001 |02/12/2013 |05