Note that there are some explanatory texts on larger screens.

plurals
  1. POReadLine() not able to read whole line
    text
    copied!<p>Today i found out why this problem occurs or how this problem occurs during reading line by line from text file using C# ReadLine(). </p> <p>Problem : </p> <p>Assume there are 3 lines in text file. Each of which has length equals to 400.(manually counted) while reading line from C# ReadLine() and checking for length in Console.WriteLine(str.length); I found out that it prints:</p> <pre><code>Line 1 =&gt; 400 Line 2 =&gt; 362 Line 3 =&gt; 38 Line 4 =&gt; 400 </code></pre> <p>I was confused and that text file has only 3 lines why its printing 4 that too with length changed. Then i quickly checked out for "\n" or "\r" or combination "\r\n" but i didn't find any, but what i found was 2 double quotes ex=> "abcd" , in second line.</p> <p>Then i changed my code to print lines itself and boy i was amaze, i was getting output in console like :</p> <pre><code>Line 1 &gt; blahblahblabablabhlabhlabhlbhaabahbbhabhblablahblhablhablahb Line 2 &gt; blablabbablablababalbalbablabal"blabablhabh Line 3 &gt; "albhalbahblablab Line 4 &gt; blahblahblabablabhlabhlabhlbhaabahbbhabhblablahblhablhablahb </code></pre> <p>now i tried removing the double quotes "" using replace function but i got same 4 lines result just without double quotes.</p> <p>Now please let me know any solution other than manual edit to overcome this scenario. Here is my code simple code:</p> <pre><code>static void Main(string[] args) { FileStream fin; string s; string fileIn = @"D:\Testing\CursedtextFile\testfile.txt"; try { fin = new FileStream(fileIn, FileMode.Open); } catch (FileNotFoundException exc) { Console.WriteLine(exc.Message + "Cannot open file."); return; } StreamReader fstr_in = new StreamReader(fin, Encoding.Default, true); int cnt = 0; while ((s = fstr_in.ReadLine()) != null) { s = s.Replace("\""," "); cnt = cnt + 1; //Console.WriteLine("Line "+cnt+" =&gt; "+s.Length); Console.WriteLine("Line " + cnt + " =&gt; " + s); } Console.ReadLine(); fstr_in.Close(); fin.Close(); } </code></pre> <p>Note: i was trying to read and upload 37 text files of 500 MB each of finance domain where i always face this issue and has to manually do the changes. :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload