streamwriter

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

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

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.

Python help to debug an error when modify a file in a stream mode

吃可爱长大的小学妹 提交于 2019-12-25 07:15:24
问题 I have the following problem. I am reading a file x,y,z as: 481492.93 6244326.24 26.56 481493.03 6244325.60 25.06 481493.17 6244324.68 22.89 481493.50 6244322.52 17.80 481492.84 6244327.05 27.84 481492.90 6244326.66 26.90 481492.86 6244327.16 27.45 481493.48 6244323.08 17.79 481492.80 6244327.80 28.30 481492.94 6244326.84 26.04 .......................... i wish to read, modify, and write on the same file (without create a back-up file because the originals file is more than 10GB) 481492.93

Flush StreamWriter at the end of its lifetime

人盡茶涼 提交于 2019-12-25 06:50:57
问题 I have a singleton-like class that can do some logging output: class Foo { private static Foo instance; private System.IO.StreamWriter os; private Foo() { this.os = System.IO.File.CreateText( "D:/tmp/test" ); } public static Foo Instance { get { if ( instance == null ) instance = new Foo(); return instance; } } public void Log( string s ) { os.Write( s ); } } When I use that in a sample program like class Program { private static void Main( string[] args ) { Foo.Instance.Log( "asdf\n" ); } }

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

Write textbox text to a file while keeping newlines

有些话、适合烂在心里 提交于 2019-12-25 02:17:10
问题 I have tried using: StreamWriter.WriteLine() StreamWriter.Write() File.WriteAllText() But all of those methods write the textbox text to the file without keeping newlines and such chars. How can I go about doing this? EDIT: private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog s = new SaveFileDialog(); s.FileName = "new_doc.txt"; s.Filter = "Text File | *.txt"; if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK) { File.WriteAllText(s.FileName,

Xml Serializing and Writer

こ雲淡風輕ζ 提交于 2019-12-25 02:09:08
问题 in one class I create with a button click a XML document: private void buttonCreate_Click(object sender, RoutedEventArgs e) { DialogResult result = folderElg.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { textBoxPath.Text = folderElg.SelectedPath; userConfigurePath = folderElg.SelectedPath; } XmlDocument toolConfig = new XmlDocument(); XmlNode myRoot; myRoot = toolConfig.CreateElement("Tool"); toolConfig.AppendChild(myRoot); toolConfig.Save(@userConfigurePath + "\\config

Redirect process standard input in Task

别说谁变了你拦得住时间么 提交于 2019-12-25 01:25:21
问题 I'm trying to start a process In C# (Java.exe running a jar file) in a seperate thread, and redirect it's StandardInput, StandardError and StandardOutput. I've successfully redirect StandardError and StandardOutput, but I am having problems with StandardInput. I'm starting the process this way: Action<object> MyAction = (object obj) => { MyProcess.Start(); MyProcess.WaitForExit(); }; Task MyTask = new Task(MyAction); MyTask.Start(); What I need then is to be able to, in my windows forms