Spaces in File

Posted on 2004-11-08
Last Modified: 2010-07-27
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???
Question by:odonovanpm
    LVL 15

    Assisted Solution

    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", "")
    data = data.Replace("\r\n", "")
    LVL 10

    Accepted Solution

    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, " ")


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now