Spaces in File

I am having trouble getting a text field from a database to display correctly in a csv file.

The ASP.NET application collects information from several database tables and returns it as one csv file. This works fine but there is one field called "Message" which is a text field in SQL Server, people use it to type in messages for deliveries with a certain product. The message field is the only one giving problems, if I replace it with any other field the format is fine.

I think that there must be line breaks (or similar) being inserted in the streamwriter when creating the csv file. How should I prepare the field for input into the file???
odonovanpmAsked:
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.

Timbo87Commented:
You can remove the line breaks by removing either \n or \r\n. Web forms use \n and Windows uses \r\n.

Assuming data is a string containing the text, try either:

data = data.Replace("\n", "")
or
data = data.Replace("\r\n", "")
0
heintalusCommented:
Try replacing the Carriage return or line breaks in the field with spaces before you output it to the csv

i.e. if you've got the data from the Message field into a variable called Msg you could do the following when outputting it to your csv file

Msg.Replace(VbCrLf, " ").Replace(VbCr, " ").Replace(VbLf, " ")

HTH
Andy
0

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
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.