Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:23:38+00:00 2026-06-17T10:23:38+00:00

I have a small function that creates a .csv file from strings stored in

  • 0

I have a small function that creates a .csv file from strings stored in a Data Grid.

Dim rowcount As Integer = DataGridView1.Rows.Count - 1
        For m As Integer = 0 To rowcount
            Dim strrowvalue As String = ""
            strrowvalue += CStr(DataGridView1.Rows(m).Cells(0).Value)
            For n As Integer = 1 To DataGridView1.Columns.Count - 1
                If DataGridView1.CurrentCell.Value Is DBNull.Value Then
                    strrowvalue += "," + "0"
                End If
                If DataGridView1.Rows(m).Cells(n).Value Is DBNull.Value Then
                    strrowvalue += "," + "0"
                Else
                    strrowvalue += "," + CStr(DataGridView1.Rows(m).Cells(n).Value)
                End If
            Next

            If m <> rowcount Then
                streamwriter.WriteLine(strrowvalue)
            End If
        Next

However after the first value a linebreak is inserted. This causes Excel and other programs to place the first value on line 1, then the rest of the values of that line are placed on line 2.

Example:

  1. 100 ,

  2. 555,333,333,666,777

  3. 200 ,

  4. 444,555,453,345,778

It should be:

  1. 100,555,333,333,666,777

  2. 200,444,555,453,345,778

Any ideas?

EDIT: Question has been modified to show that it was a linebreak that was being inserted into the string, not a space.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:23:39+00:00Added an answer on June 17, 2026 at 10:23 am

    It’s not clear from your code where the space comes from, and the best way for getting rid of the space is probably to prevent it from ever occurring in the first place.

    In addition, the space will not cause Excel to add a line break (I’ve just tested it to make sure). In fact, Excel silently swallows the space. If a line break is inserted in your case, that suggests that the character isn’t a whitespace but something else.

    Apart from that, your code for removing whitespace works. You probably forgot to assign the result to a variable:

    strrowvalue = strrowvalue.Replace(" ", "")
    

    Edit: since it’s apparently a carriage return character rather than a space, use this:

    strrowvalue = strrowvalue.Replace(vbCr, "")
    

    Or, if it’s a full Windows-style line break:

    strrowvalue = strrowvalue.Replace(vbCrLf, "")
    

    If neither of these works (weird!), try this:

    strrowvalue = strrowvalue.Replace(vbLf, "")
    

    In other news, you should use a StringBuilder here instead, it will perform much better than lots of repeated string concatenations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly recursive function, that creates a (very small) std::multimap locally for
i have small function that running on condintion, if text box value is not
In an access database I have a small function that is called on startup
I have a small C# function that takes any generic SQLDataReader and converts it
I have written a small function, which uses ElementTree to parse xml file,but it
I have a small script we're using to read in a CSV file containing
I have a loop that creates a small number of forms on a page.
I'm writing a small nginx module that reads some url pairs from a data
I have created a small function that I'm using with the onclick event... I
I have a function that dynamically creates div boxes and put an event on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.