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. Converting a .txt file to .csv file

Converting a .txt file to .csv file

Scheduled Pinned Locked Moved C#
questionhelp
7 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.
  • M Offline
    M Offline
    Mr Perfect
    wrote on last edited by
    #1

    Dear All, I need to convert a .txt file into a .csv file. How can I do this? Please help me. Thanx

    A C 2 Replies Last reply
    0
    • M Mr Perfect

      Dear All, I need to convert a .txt file into a .csv file. How can I do this? Please help me. Thanx

      A Offline
      A Offline
      andre_swnpl
      wrote on last edited by
      #2

      That will depend on what is inside the .txt file. A txt file can contain anything whereas .csv file contains some kind of delimited data. But you could try to read the txt file using a StringReader and convert the data into csv as per your requirements and the save this to csv using StringWriter.

      1 Reply Last reply
      0
      • M Mr Perfect

        Dear All, I need to convert a .txt file into a .csv file. How can I do this? Please help me. Thanx

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Mr Perfect wrote:

        I need to convert a .txt file into a .csv file. How can I do this?

        Change the file extension? Seriously - What format is the TXT file in?


        Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

        M 1 Reply Last reply
        0
        • C Colin Angus Mackay

          Mr Perfect wrote:

          I need to convert a .txt file into a .csv file. How can I do this?

          Change the file extension? Seriously - What format is the TXT file in?


          Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          M Offline
          M Offline
          Mr Perfect
          wrote on last edited by
          #4

          It contains some data seperated by delimiter.

          C 1 Reply Last reply
          0
          • M Mr Perfect

            It contains some data seperated by delimiter.

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Mr Perfect wrote:

            It contains some data seperated by delimiter.

            That's a bit of a vague file format specification there. We are trying to be helpful, but you need to help us to help you. You need to give us the information about your problem so we can help you find a solution. What sort of delimiter? What will constitute one line in the resulting CSV file? Do you really just want to replace one delimiter for another?


            Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            M 1 Reply Last reply
            0
            • C Colin Angus Mackay

              Mr Perfect wrote:

              It contains some data seperated by delimiter.

              That's a bit of a vague file format specification there. We are trying to be helpful, but you need to help us to help you. You need to give us the information about your problem so we can help you find a solution. What sort of delimiter? What will constitute one line in the resulting CSV file? Do you really just want to replace one delimiter for another?


              Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              M Offline
              M Offline
              Mr Perfect
              wrote on last edited by
              #6

              Delimiter may be a comma or semicolon or tab

              C 1 Reply Last reply
              0
              • M Mr Perfect

                Delimiter may be a comma or semicolon or tab

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                Read the entire file into a string. Use Replace to replace one delimiter with another. Save the new string to disk.


                Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                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