Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Open a <code>TextReader</code> (e.g. by <code>File.OpenText</code> - note that <a href="http://msdn.microsoft.com/en-us/library/system.io.file.aspx" rel="nofollow"><code>File</code></a> is a static class, so you <em>can't</em> create an instance of it) and repeatedly call <a href="http://msdn.microsoft.com/en-us/library/0w3csw16.aspx" rel="nofollow"><code>Read</code></a>. That returns <code>int</code> rather than <code>char</code> so it can <em>also</em> indicate end of file:</p> <pre><code>int readResult = reader.Read(); if (readResult != -1) { char nextChar = (char) readResult; // ... } </code></pre> <p>Or to loop:</p> <pre><code>int readResult; while ((readResult = reader.Read()) != -1) { char nextChar = (char) readResult; // ... } </code></pre> <p>Or for more funky goodness:</p> <pre><code>public static IEnumerable&lt;char&gt; ReadCharacters(string filename) { using (var reader = File.OpenText(filename)) { int readResult; while ((readResult = reader.Read()) != -1) { yield return (char) readResult; } } } ... foreach (char c in ReadCharacters("foo.txt")) { ... } </code></pre> <p>Note that all by default, <code>File.OpenText</code> will use an encoding of UTF-8. Specify an encoding explicitly if that isn't what you want.</p> <p>EDIT: To find the end of a line, you'd check whether the character is <code>\n</code>... you'd potentially want to handle <code>\r</code> specially too, if this is a Windows text file.</p> <p>But if you want each <em>line</em>, why not just call <code>ReadLine</code>? You can always iterate over the characters in the line afterwards...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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