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

  • SEARCH
  • Home
  • 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 9252551
In Process

The Archive Base Latest Questions

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

I have a StringBuilder I am using and I add to it from a

  • 0

I have a StringBuilder I am using and I add to it from a loop that goes through a DataGridView. What I need to do is separate the strings if there are more than one with a “, “. Then I set a label’s text from the StringBuilder. Below is a working example without the comma’s…

THIS IS THE UPDATED VERSION THAT WORKS GREAT NOW….

    Dim strUnits As New System.Text.StringBuilder
    Dim lineCount As Integer = 0

   For i = 0 To dgvLowInventory.RowCount - 1
        If dgvLowInventory.Rows(i).Cells(1).Value Is DBNull.Value Or dgvLowInventory.Rows(i).Cells(2).Value Is DBNull.Value Then
            'Skip
        Else
            If lineCount >= 1 Then
                strUnits.Append(", ")
                strUnits.Append("[" & dgvLowInventory.Rows(i).Cells(1).Value & " - " & dgvLowInventory.Rows(i).Cells(3).Value & "]")
                lineCount += 1
            Else
                strUnits.Append("[" & dgvLowInventory.Rows(i).Cells(1).Value & " - " & dgvLowInventory.Rows(i).Cells(3).Value & "]")
                lineCount += 1
            End If
        End If
    Next

    lblTestString.Text = strUnits.ToString()
  • 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-18T10:58:24+00:00Added an answer on June 18, 2026 at 10:58 am

    Keep a counter, starting at 0.

    Add 1 to the counter every time you append, after you append.

    Before appending, if the counter is greater than 0, append a ", " before appending the string.

    Alternatively, use String.Join with ", ", depending on what language you are programming in there’s usually an equivalent to this.
    http://msdn.microsoft.com/en-us/library/57a79xd0.aspx

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

Sidebar

Related Questions

I have created an app, that fetchs data from mysql using php. But when
I have a plain text file that I need to read in using C#,
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I'm have a StringBuilder that is writing content to a file. Towards the end
I don't know either my implementation have bugs or StringBuilder is going wrong. From
I have a static logging function that uses StringBuilder to concatenate a bunch of
So, I have this code that grabs a bunch of data from the database,
I have been using LiteralControl to add direct HTML code to webpages for long
I have a listview which I populate from a webservice query. Problem is that
I have a solution that works, yet it doesn't meet the QA requirements from

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.