logo
down
shadow

C# streamreader read data multiple times


C# streamreader read data multiple times

By : adhavan udavi
Date : October 17 2020, 06:10 PM
With these it helps There are only two constructors for StreamReader that take one parameter. Since "FileContent" is probably not a string, it must be a Stream of some kind. The first time it is read from it is left at the end. Therefore you must either reset it to the beginning (if it allows that), make a copy before reading, or get a new one created.
code :


Share : facebook icon twitter icon
using StreamReader.Read to read blocks of short, integer and decimal data types

using StreamReader.Read to read blocks of short, integer and decimal data types


By : user2436070
Date : March 29 2020, 07:55 AM
To fix the issue you can do My suggestion would be to not try to parse the majority of the file as you are doing now, but go for something like this:
code :
using (var reader = File.OpenText("<< filename >>"))
{
    string line;

    while ((line = reader.ReadLine()) != null)
    {
        string[] parts = line.Split(',');

        // Process the different parts of the line here.
    }
}
tick = int.Parse(parts[0]);
symbol = short.Parse(parts[1]);
value = decimal.Parse(parts[2]);
dayData[symbol][name][tick] = value;
Is it necessary to create multiple streamreader instances to read multiple files?

Is it necessary to create multiple streamreader instances to read multiple files?


By : Mohammed
Date : March 29 2020, 07:55 AM
Does that help Reading from disk is comparatively very slow. The instantiation of a StreamReader is negligible is comparison. The slow part is ReadToEnd(), not new StreamReader(). Try to avoid reading from disk if your code is too slow.
Some versions of Visual Studio ship with a profiler which will tell you exactly which methods are spending cpu/clock time of your program
Read multiple lines with StreamReader with StreamReader.Peek

Read multiple lines with StreamReader with StreamReader.Peek


By : GPM
Date : March 29 2020, 07:55 AM
To fix this issue I would strongly recommend that you separate the IO from the line handling entirely.
Instead of making your processing code use a StreamReader, pass it either an IList or an IEnumerable... if you use IList that will make it really easy to just access the lines by index (so you can easily keep track of "the key I'm processing started at line 5" or whatever), but it would mean either doing something clever or reading the whole file in one go.
C# streamreader Read(char[] buffer, int index, int count) method fails to read from file after streamreader object Posit

C# streamreader Read(char[] buffer, int index, int count) method fails to read from file after streamreader object Posit


By : Guravtar Sandhu
Date : March 29 2020, 07:55 AM
hop of those help? It's really unclear what you're asking. But, if you want to read an arbitrary number of characters from one stream reader and write them to a writer, this works:
code :
int bytesRead;
do
{
    bytesRead = SR1.Read(buffer_search, 0, buffer_search.Length);
    if (bytesRead > 0)
    {
        // TODO: process buffer_search in some way.
        SW1.Write(buffer_search, 0, bytesRead);
    }
} while (bytesRead > 0);
Streamreader reading the same line multiple times C#

Streamreader reading the same line multiple times C#


By : user3163195
Date : March 29 2020, 07:55 AM
may help you . The issue is that you only ever read the first line of the file. To solve this you need to ensure you call sr.ReadLine() on every iteration through the loop. This would look like:
code :
using (StreamReader sr = File.OpenText(datafile))
{
    string line = sr.ReadLine();
    while (line != null)
    {
        count = count ++;
        if (count % 2 == 0)
        {
            string[] splitline = line.Split(' ');
            string datanumber = splitline[0].Trim('>');
            index.Add(datanumber, count);
        }

        line = sr.ReadLine();
    }
}
Related Posts Related Posts :
  • NullReferenceException with Ckeditor 5 and ASP.NET MVC bundle error?
  • How to refresh unc path cache?
  • dllexport Struct pointers and returning uint8_t
  • Is it a good practice to have setter in the get instance property of a singleton class
  • How to sort the coordinates of a hash set in C#
  • Multiply 64-bit integers using .NET Core's hardware intrinsics
  • How to parse string data to string and long?
  • Submit Button is not working In Razor asp.net mvc
  • While loop multiple condition check with single variable
  • Inside a catch clause, how can I see an exception without a name
  • How I can use Certificate.pfx for windows exe build
  • I'm trying to detect that SQL Server Compact Edition is installed in a system or not
  • UWP Replace MainView with FullScreen Frame
  • How do I display the data of the "current user"?
  • AVX2 SIMD XOR not yielding performance improvements in .NET
  • Algorithm to find the closest time
  • Xamarin Form - How To store an image in PDF or JPEG Format in UWP
  • ModelState error: The value 'null' is not valid for nullable field
  • Pre Increment of an operator
  • MSTest Asserts fail with null reference
  • Getting random numbers after a simple math problem. Might be a local variable thing
  • Convert HTML to PDF using HTML Renderer using C# and XML to Pdf
  • Conversion failed when converting varchar value to datatype bit
  • How to edit an XML file in Streamingassets from my hololens
  • Naming a DispatcherTimer based on a string from another method?
  • How to call the default browser in the Hololens app
  • How do I close an IF statement if there is no more code to be executed with 'else'?
  • Unity3D: Is there a easy way to give a min/max to a value in the inspector?
  • The type or namespace name 'ICloudRecoEventHandler' could not be found
  • When compiling C# expression trees into methods, is it possible to access "this"?
  • Sort an array of strings in ascending order in C#
  • How detect is a method in a C# class is implementing a method from an interface?
  • How to parse a timespan in order to add it to a datetime?
  • Changing code from if-statement to switch-statement in C#
  • Linq GroupBy Clause not including items with zero count
  • How to determine the highest value in a list of properties
  • C# Custom Json.NET List serialization
  • Session Variable is null after using RedirectToAction
  • How to manipulate c# code programatically In .Net Core?
  • Modifying Windows System sounds
  • Is there a way to convert this powershell script to C#
  • Lists will show null even though assigned in constructor
  • Any way to have a `using` block that doesn't define a scope block?
  • How do I get a result from this mocked service?
  • async await losing response in c#
  • How can I pause an execution without using Thread.Sleep()
  • How to Stop In Azure Ad Authentication Sign Out ask for Which account do you want to sign out of?
  • Use operators with and without space in c#
  • Remove duplicates from comma separated list
  • Use a String variable as argument from if sentence
  • unity how to avoid scaling heritage when parenting?
  • Is there a way to do nested model binding with the [FromBody] attribute?
  • How to insert dynamic query into table using c#
  • Why Unit Testing Assert.AreEqual() method does NOT pick up my own Equals() method in the customized class
  • Unity Error: Feature 'out variable declaration'
  • What happens if my C# switch expression is non-exhaustive?
  • How Can I Select an ItemTemplate Based on a Value?
  • EF Class table name and column have same name
  • Substring issues - input string was not in a correct format
  • C# Asynchronously read data from a redirected StandardOutput
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk