How to delete CR LF in a .csv file using Vb.Net

I am working on VS 2012, Vb.Net - .Net framework 4.0

This piece of code, read the .csv file and expected to rewrite the .csv file without Carriage Return.

But now, Carriage Return is created as a new line. I have also attached the screen shot.

Along with the post, i have attached the sample csv file.

 Public Sub Test()

            Dim reader As StreamReader = New System.IO.StreamReader(File.OpenRead("D:\CSV\Test.csv"))
            Dim listA As New List(Of String)()

            If File.Exists("d:\CSV\TestOut1.csv") Then
            End If

            Dim sw As New StreamWriter("d:\CSV\TestOut1.csv")
            Dim s As String = String.Empty

            While reader.Peek() >= 0
                Dim line As String = reader.ReadLine()
                Dim values As String() = line.Split(";"c)
                s = s + line + Chr(10)
            End While
        Catch ex As Exception
        End Try

    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

skipper68Application Development ManagerCommented:
have you tried .replace(vbcrlf, "") on the 'line' or the split array of items?
Dim values As String() = line.Split(";"c).replace(vbCrLf,"")
Don ThomsonCommented:
search for the ascii character combination of CRLF  (13 and 10) and and don't write a new line

Or simply search for a  line with a length of less than 3 characters and ignore it

Not sure why your doing this - a .csv  file will always be created with the CRLF  at the end.
Every program that I've seen that imports a CSV file uses the CRLF as an end of file and stops writing
Fernando SotoRetiredCommented:
Change this line of code


to this


And see if that is what you are looking for.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

chokkaStudentAuthor Commented:
@Fernando, Great !! Thank you !! Looks like it works !!

I need to test again to confirm
chokkaStudentAuthor Commented:
Thank you !!
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.