C# - Replace newline character in a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GoalieDude
    New Member
    • Feb 2008
    • 2

    C# - Replace newline character in a text file

    My problem is that I'll receive a large excel file from a customer that has hard return in one of the cells (i.e. pressing alt + enter to make a new line in a cell) and when I export it to a text file, the value for that cell will have quotes around it and have an unknown/unreadable character (the little boxes) inline with the text. I would like to use C# to build an application to batch check for this kind of error but I can't figure out how to remove the newline character that is in the text file. Any help would be much appreciated.
    Last edited by GoalieDude; Feb 29 '08, 05:43 AM. Reason: Clarification
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I recomend reading the data in and examining what the byte values of those characters are, to make sure you have them correct.
    Then in your program you can read in the string and do a .Replace(TheVal ueOfThoseBytes, ""); to remove them.

    Comment

    • GoalieDude
      New Member
      • Feb 2008
      • 2

      #3
      Thanks - that works really well. Now my next question is that say I want to define my own delimiters to search between - in my case quotation marks - how would you go about doing that? Is it possible in C#?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well if your delimeters are already in the file, you can use the .Split() function to create an array of each of the sections between delimeters.

        Comment

        Working...