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. read a line from a text file

read a line from a text file

Scheduled Pinned Locked Moved C#
csharpcomquestion
4 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
    Tom Wright
    wrote on last edited by
    #1

    I have a CVS file that is too large for excel to read in. So, I want to read in the text file line by line and write out a new CVS file based on the key. What is the best way in C# to read in a line from a text file. I've looked at StreamReader, but I am thinking there is a better way. Thanks

    Tom Wright tawright915@gmail.com

    V A 2 Replies Last reply
    0
    • T Tom Wright

      I have a CVS file that is too large for excel to read in. So, I want to read in the text file line by line and write out a new CVS file based on the key. What is the best way in C# to read in a line from a text file. I've looked at StreamReader, but I am thinking there is a better way. Thanks

      Tom Wright tawright915@gmail.com

      V Offline
      V Offline
      Vega02
      wrote on last edited by
      #2

      Try using TextReader.ReadLine[^] to read individual lines from the file, then String.Split[^] to get an array of the individual CSV fields. This should allow you to manipulate the data as you see fit, then you can just write the modified data back out to a new file.

      V 1 Reply Last reply
      0
      • V Vega02

        Try using TextReader.ReadLine[^] to read individual lines from the file, then String.Split[^] to get an array of the individual CSV fields. This should allow you to manipulate the data as you see fit, then you can just write the modified data back out to a new file.

        V Offline
        V Offline
        Vega02
        wrote on last edited by
        #3

        BTW, StreamReader (as you pointed out) is derived from the TextReader class, so it should suffice for what you wanted.

        1 Reply Last reply
        0
        • T Tom Wright

          I have a CVS file that is too large for excel to read in. So, I want to read in the text file line by line and write out a new CVS file based on the key. What is the best way in C# to read in a line from a text file. I've looked at StreamReader, but I am thinking there is a better way. Thanks

          Tom Wright tawright915@gmail.com

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

          Depending on how complex your CSV file is..you might consider one of these solutions: 1) http://www.codeproject.com/cs/database/CsvReader.asp[^] 2) http://www.codeproject.com/cs/database/GenericParser.asp[^]

          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