Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. StreamReader problem

StreamReader problem

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tavbi
    wrote on last edited by
    #1

    Hi, In code below I convert string to stream and now I have problem. The value of stremReader.Readline() is never null. What I do wrong? byte[] bytes = System.Text.Encoding.ASCII.GetBytes(stringToPrint); MemoryStream stream = new MemoryStream(bytes); StreamReader strReader = new StreamReader(stream); while (currentLine < linesPerPage) { lineText = strReader.ReadLine(); if (lineText == null) // PROBLEM - never null break; .... more code thanks

    A E 2 Replies Last reply
    0
    • T Tavbi

      Hi, In code below I convert string to stream and now I have problem. The value of stremReader.Readline() is never null. What I do wrong? byte[] bytes = System.Text.Encoding.ASCII.GetBytes(stringToPrint); MemoryStream stream = new MemoryStream(bytes); StreamReader strReader = new StreamReader(stream); while (currentLine < linesPerPage) { lineText = strReader.ReadLine(); if (lineText == null) // PROBLEM - never null break; .... more code thanks

      A Offline
      A Offline
      Andrew Rissing
      wrote on last edited by
      #2

      I would suggest using the StreamReader[^] class:

      StringReader sr = new StringReader(stringToPrint);
      ....
      
      T 1 Reply Last reply
      0
      • T Tavbi

        Hi, In code below I convert string to stream and now I have problem. The value of stremReader.Readline() is never null. What I do wrong? byte[] bytes = System.Text.Encoding.ASCII.GetBytes(stringToPrint); MemoryStream stream = new MemoryStream(bytes); StreamReader strReader = new StreamReader(stream); while (currentLine < linesPerPage) { lineText = strReader.ReadLine(); if (lineText == null) // PROBLEM - never null break; .... more code thanks

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        try a loop like this :

        Do While strReader.Peek() >= 0
        Console.WriteLine(strReader.ReadLine())
        Loop

        T 1 Reply Last reply
        0
        • E ednrgc

          try a loop like this :

          Do While strReader.Peek() >= 0
          Console.WriteLine(strReader.ReadLine())
          Loop

          T Offline
          T Offline
          Tavbi
          wrote on last edited by
          #4

          Thanks, it works.

          1 Reply Last reply
          0
          • A Andrew Rissing

            I would suggest using the StreamReader[^] class:

            StringReader sr = new StringReader(stringToPrint);
            ....
            
            T Offline
            T Offline
            Tavbi
            wrote on last edited by
            #5

            I think you mean in stringToPrint is path to file, but it isn't. In stringToPrint is text converted from StringBuilder variable and contains more lines. I just solve problem with the suggest from second reply. Thanks for your effort.

            A 1 Reply Last reply
            0
            • T Tavbi

              I think you mean in stringToPrint is path to file, but it isn't. In stringToPrint is text converted from StringBuilder variable and contains more lines. I just solve problem with the suggest from second reply. Thanks for your effort.

              A Offline
              A Offline
              Andrew Rissing
              wrote on last edited by
              #6

              I was just providing a suggestion as to prevent needless overhead for reading the string. Grats on solving the problem.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups