Text File Manipulation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Garth Wells

    #1

    Text File Manipulation

    I need to open up a .csv and replace all adjacent commas
    (,,) with comma zero comma (,0,). Anybody have an
    example of how to do this?

    Thanks


  • Stephany Young

    #2
    Re: Text File Manipulation

    3 steps:
    Read the entire content of the file into string
    Replace all occurrences of ",," with ",0,"
    Write the string to a new file or overwite the existing file

    Check out the documentation for the StreamReader class. You will find a
    range of examples, combinations of which will help you out.


    "Garth Wells" <nobody@nowhere .comwrote in message
    news:bACTg.3620 $DU3.1968@torna do.texas.rr.com ...
    >I need to open up a .csv and replace all adjacent commas
    (,,) with comma zero comma (,0,). Anybody have an
    example of how to do this?
    >
    Thanks
    >

    Comment

    • Terry Olsen

      #3
      Re: Text File Manipulation

      MyString=MyStri ng.Replace(",," ,",0,")

      "Garth Wells" <nobody@nowhere .comwrote in message
      news:bACTg.3620 $DU3.1968@torna do.texas.rr.com ...
      >I need to open up a .csv and replace all adjacent commas
      (,,) with comma zero comma (,0,). Anybody have an
      example of how to do this?
      >
      Thanks
      >

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Text File Manipulation

        "Garth Wells" <nobody@nowhere .comschrieb:
        >I need to open up a .csv and replace all adjacent commas
        (,,) with comma zero comma (,0,). Anybody have an
        example of how to do this?

        'System.IO.Stre amReader', 'System.IO.Stre amWriter', 'String.Replace ',
        'Strings.Replac e'.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Spam Catcher

          #5
          Re: Text File Manipulation

          "Garth Wells" <nobody@nowhere .comwrote in news:bACTg.3620 $DU3.1968
          @tornado.texas. rr.com:
          I need to open up a .csv and replace all adjacent commas
          (,,) with comma zero comma (,0,). Anybody have an
          example of how to do this?
          If you're doing it on a per line basis, I would open the file using
          System.IO and reach each line. Then use String.Replace to replace all
          adjacent commas.

          Once the line is fixed, use StringBuilder to re-concatentate all the lines
          together (don't use string concatenation (i.e. String A + String B) if you
          have more than 10 - 20 lines, string concatenation slows down exponentially
          - it gets REALLY slow for large files).

          Comment

          • Izzy

            #6
            Re: Text File Manipulation

            No VB.NET required for this.

            Open the file with Notepad
            Click Edit, Click Replace
            In the "Find What" box type in ",,"
            In the "Replace With" box type in ",0,"
            Click Replace All
            Save Document
            You're done!

            If this operation has to be done over and over again, then use VB.NET
            as others have described.


            Garth Wells wrote:
            I need to open up a .csv and replace all adjacent commas
            (,,) with comma zero comma (,0,). Anybody have an
            example of how to do this?
            >
            Thanks

            Comment

            • Terry Olsen

              #7
              Re: Text File Manipulation

              Touche'

              "Izzy" <israel.richner @gmail.comwrote in message
              news:1159737029 .780520.189350@ h48g2000cwc.goo glegroups.com.. .
              No VB.NET required for this.
              >
              Open the file with Notepad
              Click Edit, Click Replace
              In the "Find What" box type in ",,"
              In the "Replace With" box type in ",0,"
              Click Replace All
              Save Document
              You're done!
              >
              If this operation has to be done over and over again, then use VB.NET
              as others have described.
              >
              >
              Garth Wells wrote:
              >I need to open up a .csv and replace all adjacent commas
              >(,,) with comma zero comma (,0,). Anybody have an
              >example of how to do this?
              >>
              >Thanks
              >

              Comment

              Working...