streamreader

StreamReader is too greedy

℡╲_俬逩灬. 提交于 2020-01-30 08:05:20
问题 I'm trying to process part of a text file, and write the remainder of the text file to a cloud blob using UploadFromStream . The problem is that the StreamReader appears to be grabbing too much content from the underlying stream, and so the subsequent write does nothing. Text file: 3 Col1,String Col2,Integer Col3,Boolean abc,123,True def,3456,False ghijkl,532,True mnop,1211,False Code: using (var stream = File.OpenRead("c:\\test\\testinput.txt")) using (var reader = new StreamReader(stream))

C# System.Diagnostics.Process redirecting Standard Out for large amounts of data

为君一笑 提交于 2020-01-28 11:12:45
问题 I running an exe from a .NET app and trying to redirect standard out to a streamreader. The problem is that when I do myprocess.exe >> out.txt out.txt is close to 14mb. When I do the command line version it is very fast but when I run the process from my csharp app it is excruciatingly slow because I believe the default streamreader flushes every 4096 bytes. Is there a way to change the default stream reader for the Process object? 回答1: I haven't tried, but it looks like the asynchronous

C# System.Diagnostics.Process redirecting Standard Out for large amounts of data

人走茶凉 提交于 2020-01-28 11:12:20
问题 I running an exe from a .NET app and trying to redirect standard out to a streamreader. The problem is that when I do myprocess.exe >> out.txt out.txt is close to 14mb. When I do the command line version it is very fast but when I run the process from my csharp app it is excruciatingly slow because I believe the default streamreader flushes every 4096 bytes. Is there a way to change the default stream reader for the Process object? 回答1: I haven't tried, but it looks like the asynchronous

Getting Sum Of Numbers In Each Line Of File

a 夏天 提交于 2020-01-26 01:45:06
问题 i have a file that there is some numbers that i want to sum number one with number two in each line.here is numbers in my file: -944 -857 -158 356 540 70 15 148 for example i want to sum -944 and -857 what should i do?? i did it like the code below to check whats the numbers and the output is -158 and 15(it doesnt show -944 and 540 !!!): StreamReader ar = new StreamReader(@"C:\Users\arash\Desktop\problem1 (3).in"); while (ar.ReadLine() != null) { string[] spl = ar.ReadLine().Split(' ');

check if string exists in a file

 ̄綄美尐妖づ 提交于 2020-01-22 12:42:30
问题 I have the following piece of code which opens a text file and reads all the lines in the file and storing it into a string array. Which then checks if the string is present in the array. However the issue I'm facing is that whenever a string is found, it always shows "there is a match" as well as "there is no match". Any idea how to fix this? check this code: using (StreamReader sr = File.OpenText(path)) { string[] lines = File.ReadAllLines(path); for (int x = 0; x < lines.Length - 1; x++) {

Compressed content in a byte array to uncompressed in a string

我怕爱的太早我们不能终老 提交于 2020-01-14 03:08:27
问题 How can we create a simple function to take the compressed content from an array of byte (compressed with Deflate method, ANSI encoded) and express it in a string? I go with this one : public string UnzipString3(byte[] byteArrayCompressedContent) { int compressedSize = byteArrayCompressedContent.Length; try { using (MemoryStream inputMemoryStream = new MemoryStream(byteArrayCompressedContent)) { //I need to consume the first 2 bytes to be able read the stream //If I consume 0 or 4, I can't

OutOfMemory errors using large datatables with ClosedXML

风流意气都作罢 提交于 2020-01-07 02:57:13
问题 I have an issue creating worksheets when adding large DataTables. I am getting out of memory errors. I turned off the event tracking as suggested to improve performance and memory consumption but I am still experiencing these errors. Here is some sample code: public void SaveWorkBook(string xlFileName, DataSet dataSet) { using (var xlWorkBook = new XLWorkbook(XLEventTracking.Disabled)) { xlWorkBook.AddWorksheet(dataSet); xlWorkBook.SaveAs(xlFileName); } } public void SaveWorkBook(string

Best way to read data and store from file?

限于喜欢 提交于 2020-01-06 15:50:55
问题 I have a text file which stores data in this manner: Player name: NAME HERE Speed: 7 Strength: 9 Stamina: 4 Player name: ANOTHER NAME HERE Speed: 5 Strength: 8 Stamina: 3 The same file contains about fifteen different players, and I want to gather values from each of them, store in a temporary race variable, then calculate the mean value of the speed strength and stamina and present a winner. My first idea was to use regular expression but I am currently investigating if there are another,

c# Remove a dynamically created checkbox based on a button click

主宰稳场 提交于 2020-01-06 06:45:22
问题 I'm lost. I want to remove a value from a text file. The value is a checkbox.Name. I want to open a text file, find the corresponding username in the textfile, remove it and save the file based on a button click. Here is how I get the checkbox.Name public static void getPermText(System.Windows.Forms.Form targetForm) { Stream fileStream = File.Open(dataFolder + PermFile, FileMode.Open); StreamReader reader = new StreamReader(fileStream); string line = null; line = reader.ReadToEnd(); string[]

Reading specific lines with unknown placement in C#

半城伤御伤魂 提交于 2020-01-06 04:12:24
问题 I am trying to code a program to read out user-groups from a .txt-file and to put said groups into a listbox. An example for a group list would be the following: User ------------- Group1 Group2 Group3 [space] [space] next user Every user has is in an unknown amount of groups, thats why there are two spaces, just to seperate everything. Here is my progress so far: private void Button_Click(object sender, RoutedEventArgs e) { //users.txt contains all users //in the same directory there are